import * as XLSX from "xlsx";
import { saveAs } from "file-saver";
import moment from "moment";
import ExcelJS from "exceljs";
import PizZip from "pizzip";
import Docxtemplater from "docxtemplater";
// import  template1 from "../public/template1.docx"
// import  template2 from "../public/template2.docx"
// import  template3 from "../public/template3.docx"
// import  template4 from "../public/template4.docx"
// import  template5 from "../public/template5.docx"

export function exportXlsxFile(oriData, template, fileName, type) {
  try {
    // 创建标题数组
    const headers = Object.values(template);

    // 创建数据数组
    const data = oriData.map((obj) =>
      headers.map(
        (header) =>
          obj[Object.keys(template).find((key) => template[key] === header)]
      )
    );

    // 合并标题和数据
    const output = [headers, ...data];

    // 使用 XLSX 工具将数据转换为工作表
    const ws = XLSX.utils.aoa_to_sheet(output);

    // 设置第一行的字体样式为加粗
    const range = XLSX.utils.decode_range(ws["!ref"]);
    for (let C = range.s.c; C <= range.e.c; ++C) {
      const address = XLSX.utils.encode_col(C) + "1"; // 1表示第一行
      if (!ws[address]) continue;
      ws[address].s = {
        font: {
          bold: true,
        },
      };
    }

    if (type == "report") {
      // 设置列的宽度
      ws["!cols"] = [
        { wch: 30 }, // 第一列的宽度
        { wch: 20 }, // 第二列的宽度
        { wch: 80 }, // 第三列的宽度
        { wch: 80 }, // 第四列的宽度
      ];
      ws["!rows"] = output.map(() => {
        return { hpx: 80 };
      });
    } else if (type == "words") {
      // 设置列的宽度
      ws["!cols"] = [
        { wch: 30 }, // 第一列的宽度
        { wch: 30 }, // 第二列的宽度
        { wch: 30 }, // 第三列的宽度
      ];
    }

    // 将工作表添加到工作簿
    const wb = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(wb, ws, "Sheet1");

    // 使用 XLSX 写入工作簿并保存为 Blob
    const buffer = XLSX.write(wb, { bookType: "xlsx", type: "array" });

    // 使用 file-saver 保存 Blob
    saveAs(
      new Blob([buffer], { type: "application/octet-stream" }),
      `${fileName}.xlsx`
    );
  } catch (error) {
    console.log("exportXlsxFeil error:", error);
  }
}
//颈动脉
const a_params = {
  0: [
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      左侧内膜: "",
      左侧血流充盈程度: "",
      左侧彩色亮度: "",
      左侧色彩分布: "",
      "左侧频谱-边缘": "",
      "左侧频谱-清晰度": "",
      "左侧频谱-左侧": "",
      右侧内膜: "",
      右侧血流充盈程度: "",
      右侧彩色亮度: "",
      右侧色彩分布: "",
      "右侧频谱-边缘": "",
      "右侧频谱-清晰度": "",
      "右侧频谱-形态": "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      左侧内膜: "",
      左侧血流充盈程度: "",
      左侧彩色亮度: "",
      左侧色彩分布: "",
      "左侧频谱-边缘": "",
      "左侧频谱-清晰度": "",
      "左侧频谱-左侧": "",
      右侧内膜: "",
      右侧血流充盈程度: "",
      右侧彩色亮度: "",
      右侧色彩分布: "",
      "右侧频谱-边缘": "",
      "右侧频谱-清晰度": "",
      "右侧频谱-形态": "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      左侧内膜: "",
      左侧血流充盈程度: "",
      左侧彩色亮度: "",
      左侧色彩分布: "",
      "左侧频谱-边缘": "",
      "左侧频谱-清晰度": "",
      "左侧频谱-左侧": "",
      右侧内膜: "",
      右侧血流充盈程度: "",
      右侧彩色亮度: "",
      右侧色彩分布: "",
      "右侧频谱-边缘": "",
      "右侧频谱-清晰度": "",
      "右侧频谱-形态": "",
    },
  ],
  1: [
    {
      评估项目: "",
      评估日期: "",
      左侧颈总动脉横切面: "",
      左侧窦部横切面: "",
      左侧颈内及颈外动脉横切面: "",
      左侧颈内及颈外动脉纵切面: "",
      左侧颈总动脉纵切面: "",
      左侧颈总动脉起始部纵切面: "",
      右侧颈总动脉横切面: "",
      右侧窦部横切面: "",
      右侧颈内及颈外动脉横切面: "",
      右侧颈内及颈外动脉纵切面: "",
      右侧颈总动脉纵切面: "",
      右侧颈总动脉起始部纵切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      左侧颈总动脉横切面: "",
      左侧窦部横切面: "",
      左侧颈内及颈外动脉横切面: "",
      左侧颈内及颈外动脉纵切面: "",
      左侧颈总动脉纵切面: "",
      左侧颈总动脉起始部纵切面: "",
      右侧颈总动脉横切面: "",
      右侧窦部横切面: "",
      右侧颈内及颈外动脉横切面: "",
      右侧颈内及颈外动脉纵切面: "",
      右侧颈总动脉纵切面: "",
      右侧颈总动脉起始部纵切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      左侧颈总动脉横切面: "",
      左侧窦部横切面: "",
      左侧颈内及颈外动脉横切面: "",
      左侧颈内及颈外动脉纵切面: "",
      左侧颈总动脉纵切面: "",
      左侧颈总动脉起始部纵切面: "",
      右侧颈总动脉横切面: "",
      右侧窦部横切面: "",
      右侧颈内及颈外动脉横切面: "",
      右侧颈内及颈外动脉纵切面: "",
      右侧颈总动脉纵切面: "",
      右侧颈总动脉起始部纵切面: "",
    },
  ],
  2: {
    评估医生: "",
    评估日期: "",
    扫查完整: "",
    左侧内膜: "",
    左侧血流充盈程度: "",
    左侧彩色亮度: "",
    左侧色彩分布: "",
    "左侧频谱-边缘": "",
    "左侧频谱-清晰度": "",
    "左侧频谱-左侧": "",
    右侧内膜: "",
    右侧血流充盈程度: "",
    右侧彩色亮度: "",
    右侧色彩分布: "",
    "右侧频谱-边缘": "",
    "右侧频谱-清晰度": "",
    "右侧频谱-形态": "",
  },
  3: {
    评估医生: "",
    评估日期: "",
    左侧声像图: "",
    左侧斑块: "",
    左侧血管闭塞: "",
    右侧声像图: "",
    右侧斑块: "",
    右侧血管闭塞: "",
  },
  4: {
    开始时间: "",
    结束时间: "",
    "使用总时长(自动计算)(秒)": "",
    "左侧颈总动脉的管径(mm)": "",
    "左侧颈总内中膜厚度(IMT) (mm)": "",
    "左侧颈总收缩期峰值流速(cm/s)": "",
    "左侧颈总舒张末期流速(cm/s)": "",
    "右侧颈总动脉的管径(mm)": "",
    "右侧颈总内中膜厚度(IMT) (mm)(mm)": "",
    "右侧颈总收缩期峰值流速 (cm/s)(mm)": "",
    "右侧颈总舒张末期流速(cm/s)(mm)": "",
  },
};
//甲状腺
const t_params = {
  0: [
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
      彩色亮度: "",
      色彩分布: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
      彩色亮度: "",
      色彩分布: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
      彩色亮度: "",
      色彩分布: "",
    },
  ],
  1: [
    {
      评估项目: "",
      评估日期: "",
      峡部横切面: "",
      左侧叶横切面: "",
      左侧叶纵切面: "",
      右侧叶横切面: "",
      右侧叶纵切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      峡部横切面: "",
      左侧叶横切面: "",
      左侧叶纵切面: "",
      右侧叶横切面: "",
      右侧叶纵切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      峡部横切面: "",
      左侧叶横切面: "",
      左侧叶纵切面: "",
      右侧叶横切面: "",
      右侧叶纵切面: "",
    },
  ],
  2: {
    评估医生: "",
    评估日期: "",
    扫查完整: "",
    形态轮廓: "",
    细腻程度: "",
    彩色亮度: "",
    色彩分布: "",
  },
  3: {
    评估医生: "",
    评估日期: "",
    声像图: "",
    弥漫性异常: "",
    实质性回声: "",
    局限性异常回声: "",
    局限性异常回声强度: "",
    局限性异常回声形态: "",
  },
  4: {
    开始时间: "",
    结束时间: "",
    "使用总时长(自动计算)(秒)": "",
    "左侧叶前后径(mm)": "",
    "左侧叶左右径(mm)": "",
    "左侧叶上下径(mm)": "",
    "右侧叶前后径(mm)": "",
    "右侧叶左右径(mm)": "",
    "右侧叶上下径(mm)": "",
    "峡部前后径(mm)": "",
  },
};
//泌尿
const k_params = {
  0: [
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      左肾形态轮廓: "",
      "左肾皮质、髓质显示": "",
      左肾彩色亮度: "",
      左肾色彩分布: "",
      右肾形态轮廓: "",
      "右肾皮质、髓质显示": "",
      右肾彩色亮度: "",
      右肾色彩分布: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      左肾形态轮廓: "",
      "左肾皮质、髓质显示": "",
      左肾彩色亮度: "",
      左肾色彩分布: "",
      右肾形态轮廓: "",
      "右肾皮质、髓质显示": "",
      右肾彩色亮度: "",
      右肾色彩分布: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      左肾形态轮廓: "",
      "左肾皮质、髓质显示": "",
      左肾彩色亮度: "",
      左肾色彩分布: "",
      右肾形态轮廓: "",
      "右肾皮质、髓质显示": "",
      右肾彩色亮度: "",
      右肾色彩分布: "",
    },
  ],
  1: [
    {
      评估项目: "",
      评估日期: "",
      左肾脏的长轴切面: "",
      右肾脏的长轴切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      左肾脏的长轴切面: "",
      右肾脏的长轴切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      左肾脏的长轴切面: "",
      右肾脏的长轴切面: "",
    },
  ],
  2: {
    评估医生: "",
    评估日期: "",
    扫查完整: "",
    左肾形态轮廓: "",
    "左肾皮质、髓质显示": "",
    左肾彩色亮度: "",
    左肾色彩分布: "",
    右肾形态轮廓: "",
    "右肾皮质、髓质显示": "",
    右肾彩色亮度: "",
    右肾色彩分布: "",
  },
  3: {
    评估医生: "",
    评估日期: "",
    左肾声像图: "",
    左肾实质性回声: "",
    左肾局限性异常回声: "",
    左肾局限性异常回声强度: "",
    左肾局限性异常回声形态: "",
    右肾声像图: "",
    右肾实质性回声: "",
    右肾局限性异常回声: "",
    右肾局限性异常回声强度: "",
    右肾局限性异常回声形态: "",
  },
  4: {
    开始时间: "",
    结束时间: "",
    "使用总时长(自动计算)(秒)": "",
    "左肾脏上下径(mm)": "",
    "左肾脏前后径(mm)": "",
    "右肾脏上下径(mm)": "",
    "右肾脏前后径(mm)": "",
  },
};
//肝脏
const l_params = {
  0: [
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
      管道结构: "",
      血管充盈度: "",
      彩色亮度: "",
      色彩分布: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
      管道结构: "",
      血管充盈度: "",
      彩色亮度: "",
      色彩分布: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
      管道结构: "",
      血管充盈度: "",
      彩色亮度: "",
      色彩分布: "",
    },
  ],
  1: [
    {
      评估项目: "",
      评估日期: "",
      肝左叶经腹主动脉长轴纵切面: "",
      肝左叶斜切面: "",
      肋下斜切第二肝门切面: "",
      右肋下右肝及右肾纵切面: "",
      右肋间经第一肝门斜切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      肝左叶经腹主动脉长轴纵切面: "",
      肝左叶斜切面: "",
      肋下斜切第二肝门切面: "",
      右肋下右肝及右肾纵切面: "",
      右肋间经第一肝门斜切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      肝左叶经腹主动脉长轴纵切面: "",
      肝左叶斜切面: "",
      肋下斜切第二肝门切面: "",
      右肋下右肝及右肾纵切面: "",
      右肋间经第一肝门斜切面: "",
    },
  ],
  2: {
    评估医生: "",
    评估日期: "",
    扫查完整: "",
    形态轮廓: "",
    细腻程度: "",
    管道结构: "",
    血管充盈度: "",
    彩色亮度: "",
    色彩分布: "",
  },
  3: {
    评估医生: "",
    评估日期: "",
    声像图: "",
    肝实质回声弥漫性增强: "",
    实质回声: "",
    局限性异常回声: "",
    局限性异常回声强度: "",
    局限性异常回声形态: "",
  },
  4: {
    开始时间: "",
    结束时间: "",
    "使用总时长(自动计算)(秒)": "",
    "肝左叶上下径(mm)": "",
    "肝左叶前后径(mm)": "",
    "肝右叶斜径(mm)": "",
    "肝门静脉主干内径(mm)": "",
  },
};
//胆囊
const g_params = {
  0: [
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      胆囊壁: "",
      胆囊腔: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      胆囊壁: "",
      胆囊腔: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      胆囊壁: "",
      胆囊腔: "",
    },
  ],
  1: [
    {
      评估项目: "",
      评估日期: "",
      胆囊长轴纵切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      胆囊长轴纵切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      胆囊长轴纵切面: "",
    },
  ],
  2: {
    评估医生: "",
    评估日期: "",
    扫查完整: "",
    胆囊壁: "",
    胆囊腔: "",
  },
  3: {
    评估医生: "",
    评估日期: "",
    声像图: "",
    胆囊壁异常: "",
    胆囊腔异常回声: "",
  },
  4: {
    开始时间: "",
    结束时间: "",
    "使用总时长(自动计算)(秒)": "",
    "胆囊长径(mm)": "",
    "胆囊短径(mm)": "",
  },
};
//胰腺
const p_params = {
  0: [
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
    },
  ],
  1: [
    {
      评估项目: "",
      评估日期: "",
      胰腺长轴切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      胰腺长轴切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      胰腺长轴切面: "",
    },
  ],
  2: {
    评估医生: "",
    评估日期: "",
    扫查完整: "",
    形态轮廓: "",
    细腻程度: "",
  },
  3: {
    评估医生: "",
    评估日期: "",
    声像图: "",
    实质回声: "",
    局限性异常回声: "",
    局限性异常回声强度: "",
    局限性异常回声形态: "",
  },
  4: {
    开始时间: "",
    结束时间: "",
    "使用总时长(自动计算)(秒)": "",
    "胰体前后径(mm)": "",
  },
};
//脾脏
const s_params = {
  0: [
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
      脾门血管: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
      脾门血管: "",
    },
    {
      评估项目: "",
      评估日期: "",
      扫查完整: "",
      形态轮廓: "",
      细腻程度: "",
      脾门血管: "",
    },
  ],
  1: [
    {
      评估项目: "",
      评估日期: "",
      脾脏纵切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      脾脏纵切面: "",
    },
    {
      评估项目: "",
      评估日期: "",
      脾脏纵切面: "",
    },
  ],
  2: {
    评估医生: "",
    评估日期: "",
    扫查完整: "",
    形态轮廓: "",
    细腻程度: "",
    脾门血管: "",
  },
  3: {
    评估医生: "",
    评估日期: "",
    声像图: "",
    实质回声: "",
    局限性异常回声: "",
    局限性异常回声强度: "",
    局限性异常回声形态: "",
  },
  4: {
    开始时间: "",
    结束时间: "",
    "脾脏长径(mm)": "",
    "脾脏厚径(mm)": "",
    "脾门部脾静脉直径(mm)": "",
  },
};
export function dellDataByRecord(record) {
  if (!record.forms || record.forms.length == 0) {
    return false;
  }
  if (record.pos != "腹部") {
    let measureInfo,
      measureData,
      forms,
      params,
      params_0 = [],
      params_1 = [],
      params_2,
      params_3;
    forms = record.forms;
    forms.forEach((item) => {
      if (item.evaluationResult) {
        const evaluationResult = JSON.parse(item.evaluationResult);
        if (item.evaluationID == 0 && item.level == 6) {
          const param = {
            评估项目: item.doctorName,
            评估日期: item.finishDate,
            ...evaluationResult[item.pos],
          };
          params_0.push(param);
        } else if (item.evaluationID == 1 && item.level == 6) {
          const param = {
            评估项目: item.doctorName,
            评估日期: item.finishDate,
            ...evaluationResult[item.pos],
          };
          params_1.push(param);
        } else if (item.evaluationID == 0 && item.level == 7) {
          params_2 = {
            评估医生: item.doctorName,
            评估日期: item.finishDate,
            ...evaluationResult[item.pos],
          };
        } else if (item.evaluationID == 2 && item.level == 7) {
          params_3 = {
            评估医生: item.doctorName,
            评估日期: item.finishDate,
            ...evaluationResult[item.pos],
          };
        }
      } else {
        if (record.pos == "颈动脉") {
          if (item.evaluationID == 0 && item.level == 6) {
            params_0.push(a_params[0][0]);
          } else if (item.evaluationID == 1 && item.level == 6) {
            params_1.push(a_params[1][0]);
          } else if (item.evaluationID == 0 && item.level == 7) {
            params_2 = a_params[2];
          } else if (item.evaluationID == 2 && item.level == 7) {
            params_3 = a_params[3];
          }
        } else if (record.pos == "甲状腺") {
          if (item.evaluationID == 0 && item.level == 6) {
            params_0.push(t_params[0][0]);
          } else if (item.evaluationID == 1 && item.level == 6) {
            params_1.push(t_params[1][0]);
          } else if (item.evaluationID == 0 && item.level == 7) {
            params_2 = t_params[2];
          } else if (item.evaluationID == 2 && item.level == 7) {
            params_3 = t_params[3];
          }
        } else if (record.pos == "泌尿" || record.pos == "肾脏") {
          if (item.evaluationID == 0 && item.level == 6) {
            params_0.push(k_params[0][0]);
          } else if (item.evaluationID == 1 && item.level == 6) {
            params_1.push(k_params[1][0]);
          } else if (item.evaluationID == 0 && item.level == 7) {
            params_2 = k_params[2];
          } else if (item.evaluationID == 2 && item.level == 7) {
            params_3 = k_params[3];
          }
        }
      }
    });
    if (record.measureInfo) {
      measureInfo = JSON.parse(record.measureInfo);
    }
    console.log("forms", forms);
    console.log("measureInfo", measureInfo);
    if (measureInfo) {
      if (record.pos == "颈动脉") {
        const scanIMTInfo = measureInfo.scanIMTInfo;
        const vesselDiameterInfo = measureInfo.vesselDiameterInfo;
        const psedInfo = measureInfo.psedInfo;
        const left_psedInfo = psedInfo ? psedInfo[2] : "";
        const right_psedInfo = psedInfo ? psedInfo[4] : "";
        const left_psedInfo_1 = left_psedInfo
          ? left_psedInfo.split("/")[0]
          : "";
        const left_psedInfo_2 = left_psedInfo
          ? left_psedInfo.split("/")[1]
          : "";
        const left_psedInfo_3 = right_psedInfo
          ? right_psedInfo.split("/")[0]
          : "";
        const left_psedInfo_4 = right_psedInfo
          ? right_psedInfo.split("/")[1]
          : "";

        measureData = {
          开始时间: record.startAt,
          结束时间: record.endAt,
          "使用总时长(自动计算)(秒)": timeDifference(
            record.startAt,
            record.endAt
          ),
          "左侧颈总动脉的管径(mm)": vesselDiameterInfo[19]
            ? vesselDiameterInfo[19]
            : "",
          "左侧颈总内中膜厚度(IMT) (mm)": scanIMTInfo[19]
            ? scanIMTInfo[19]
            : "",
          "左侧颈总收缩期峰值流速(cm/s)": left_psedInfo_1,
          "左侧颈总舒张末期流速(cm/s)": left_psedInfo_2,
          "右侧颈总动脉的管径(mm)": vesselDiameterInfo[33]
            ? vesselDiameterInfo[33]
            : "",
          "右侧颈总内中膜厚度(IMT) (mm)": scanIMTInfo[33]
            ? scanIMTInfo[33]
            : "",
          "右侧颈总收缩期峰值流速(cm/s)": left_psedInfo_3,
          "右侧颈总舒张末期流速(cm/s)": left_psedInfo_4,
        };
      } else if (record.pos == "甲状腺") {
        const thyroid_measure = measureInfo.thyroid_measure;
        measureData = {
          开始时间: record.startAt,
          结束时间: record.endAt,
          "使用总时长(自动计算)(秒)": timeDifference(
            record.startAt,
            record.endAt
          ),
          "峡部前后径(mm)": thyroid_measure[0] ? thyroid_measure[0] * 10 : "",
          "右侧叶左右径(mm)": thyroid_measure[1] ? thyroid_measure[1] * 10 : "",
          "右侧叶前后径(mm)": thyroid_measure[2] ? thyroid_measure[2] * 10 : "",
          "右侧叶上下径(mm)": thyroid_measure[3] ? thyroid_measure[3] * 10 : "",
          "左侧叶左右径(mm)": thyroid_measure[4] ? thyroid_measure[4] * 10 : "",
          "左侧叶前后径(mm)": thyroid_measure[5] ? thyroid_measure[5] * 10 : "",
          "左侧叶上下径(mm)": thyroid_measure[6] ? thyroid_measure[6] * 10 : "",
        };
      } else if (record.pos == "泌尿" || record.pos == "肾脏") {
        const urinaryMeasure = measureInfo.urinaryMeasure;
        measureData = {
          开始时间: record.startAt,
          结束时间: record.endAt,
          "使用总时长(自动计算)(秒)": timeDifference(
            record.startAt,
            record.endAt
          ),
          "左肾脏上下径(mm)": urinaryMeasure[5011]
            ? urinaryMeasure[5011] * 10
            : "",
          "左肾脏前后径(mm)": urinaryMeasure[5012]
            ? urinaryMeasure[5012] * 10
            : "",
          "右肾脏上下径(mm)": urinaryMeasure[5021]
            ? urinaryMeasure[5021] * 10
            : "",
          "右肾脏前后径(mm)": urinaryMeasure[5022]
            ? urinaryMeasure[5022] * 10
            : "",
        };
      }
    } else {
      if (record.pos == "颈动脉") {
        measureData = a_params[4];
      } else if (record.pos == "甲状腺") {
        measureData = t_params[4];
      } else if (record.pos == "泌尿" || record.pos == "肾脏") {
        measureData = k_params[4];
      }
    }

    params = {
      0: params_0,
      1: params_1,
      2: params_2,
      3: params_3,
      4: measureData,
    };
    return params;
  } else {
    let measureInfo,
      measureData_liver,
      measureData_gallbladder,
      measureData_pancreas,
      measureData_spleen,
      forms,
      params,
      params_liver,
      params_liver_0 = [],
      params_liver_1 = [],
      params_liver_2,
      params_liver_3,
      params_gallbladder,
      params_gallbladder_0 = [],
      params_gallbladder_1 = [],
      params_gallbladder_2,
      params_gallbladder_3,
      params_pancreas,
      params_pancreas_0 = [],
      params_pancreas_1 = [],
      params_pancreas_2,
      params_pancreas_3,
      params_spleen,
      params_spleen_0 = [],
      params_spleen_1 = [],
      params_spleen_2,
      params_spleen_3;

    forms = record.forms;
    forms.forEach((item) => {
      console.log("evaluationResult :", item.evaluationResult);
      if (item.evaluationResult) {
        const evaluationResult = JSON.parse(item.evaluationResult);
        if (item.evaluationID == 0 && item.level == 6) {
          for (const p in evaluationResult) {
            if (p == "肝脏") {
              const param = {
                评估项目: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
              params_liver_0.push(param);
            } else if (p == "胆囊") {
              const param = {
                评估项目: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
              params_gallbladder_0.push(param);
            } else if (p == "胰腺") {
              const param = {
                评估项目: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
              params_pancreas_0.push(param);
            } else if (p == "脾脏") {
              const param = {
                评估项目: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
              params_spleen_0.push(param);
            }
          }
        } else if (item.evaluationID == 1 && item.level == 6) {
          for (const p in evaluationResult) {
            if (p == "肝脏") {
              const param = {
                评估项目: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
              params_liver_1.push(param);
            } else if (p == "胆囊") {
              const param = {
                评估项目: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
              params_gallbladder_1.push(param);
            } else if (p == "胰腺") {
              const param = {
                评估项目: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
              params_pancreas_1.push(param);
            } else if (p == "脾脏") {
              const param = {
                评估项目: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
              params_spleen_1.push(param);
            }
          }
        } else if (item.evaluationID == 0 && item.level == 7) {
          for (const p in evaluationResult) {
            if (p == "肝脏") {
              params_liver_2 = {
                评估医生: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
            } else if (p == "胆囊") {
              params_gallbladder_2 = {
                评估医生: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
            } else if (p == "胰腺") {
              params_pancreas_2 = {
                评估医生: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
            } else if (p == "脾脏") {
              params_spleen_2 = {
                评估医生: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
            }
          }
        } else if (item.evaluationID == 2 && item.level == 7) {
          for (const p in evaluationResult) {
            if (p == "肝脏") {
              params_liver_3 = {
                评估医生: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
            } else if (p == "胆囊") {
              params_gallbladder_3 = {
                评估医生: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
            } else if (p == "胰腺") {
              params_pancreas_3 = {
                评估医生: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
            } else if (p == "脾脏") {
              params_spleen_3 = {
                评估医生: item.doctorName,
                评估日期: item.finishDate,
                ...evaluationResult[p],
              };
            }
          }
        }
      } else {
        if (item.evaluationID == 0 && item.level == 6) {
          params_liver_0.push(l_params[0][0]);
          params_gallbladder_0.push(g_params[0][0]);
          params_pancreas_0.push(p_params[0][0]);
          params_spleen_0.push(s_params[0][0]);
        } else if (item.evaluationID == 1 && item.level == 6) {
          params_liver_1.push(l_params[1][0]);
          params_gallbladder_1.push(g_params[1][0]);
          params_pancreas_1.push(p_params[1][0]);
          params_spleen_1.push(s_params[1][0]);
        } else if (item.evaluationID == 0 && item.level == 7) {
          params_liver_2 = l_params[2];
          params_gallbladder_2 = g_params[2];
          params_pancreas_2 = p_params[2];
          params_spleen_2 = s_params[2];
        } else if (item.evaluationID == 2 && item.level == 7) {
          params_liver_3 = l_params[3];
          params_gallbladder_3 = g_params[3];
          params_pancreas_3 = p_params[3];
          params_spleen_3 = s_params[3];
        }
      }
    });

    if (record.measureInfo) {
      measureInfo = JSON.parse(record.measureInfo);
      if (measureInfo) {
        const digestiveMeasure = measureInfo.digestiveMeasure;
        const spleenMeasure = measureInfo.spleenMeasure;
        measureData_liver = {
          开始时间: record.startAt,
          结束时间: record.endAt,
          "使用总时长(自动计算)(秒)": timeDifference(
            record.startAt,
            record.endAt
          ),
          "肝左叶上下径(mm)": digestiveMeasure[3011]
            ? digestiveMeasure[3011] * 10
            : "",
          "肝左叶前后径(mm)": digestiveMeasure[3012]
            ? digestiveMeasure[3012] * 10
            : "",
          "肝右叶斜径(mm)": digestiveMeasure[3021]
            ? digestiveMeasure[3021] * 10
            : "",
          "肝门静脉主干内径(mm)": digestiveMeasure[3051]
            ? digestiveMeasure[3051] * 10
            : "",
        };
        measureData_gallbladder = {
          开始时间: record.startAt,
          结束时间: record.endAt,
          "使用总时长(自动计算)(秒)": timeDifference(
            record.startAt,
            record.endAt
          ),
          "胆囊长径(mm)": digestiveMeasure[3031]
            ? digestiveMeasure[3031] * 10
            : "",
          "胆囊短径(mm)": digestiveMeasure[3032]
            ? digestiveMeasure[3032] * 10
            : "",
        };
        measureData_pancreas = {
          开始时间: record.startAt,
          结束时间: record.endAt,
          "使用总时长(自动计算)(秒)": timeDifference(
            record.startAt,
            record.endAt
          ),
          "胰体前后径(mm)": digestiveMeasure[3061]
            ? digestiveMeasure[3061] * 10
            : "",
        };
        measureData_spleen = {
          开始时间: record.startAt,
          结束时间: record.endAt,
          "使用总时长(自动计算)(秒)": timeDifference(
            record.startAt,
            record.endAt
          ),
          "脾脏长径(mm)": spleenMeasure[4011] ? spleenMeasure[4011] * 10 : "",
          "脾脏厚径(mm)": spleenMeasure[4012] ? spleenMeasure[4012] * 10 : "",
          "脾门部脾静脉直径(mm)": spleenMeasure[4021]
            ? spleenMeasure[4021] * 10
            : "",
        };
      } else {
        measureData_liver = l_params[4];
        measureData_gallbladder = g_params[4];
        measureData_pancreas = p_params[4];
        measureData_spleen = s_params[4];
      }
    }

    console.log("forms", forms);
    console.log("measureInfo", measureInfo);

    params_liver = {
      0: params_liver_0,
      1: params_liver_1,
      2: params_liver_2,
      3: params_liver_3,
      4: measureData_liver,
    };
    params_gallbladder = {
      0: params_gallbladder_0,
      1: params_gallbladder_1,
      2: params_gallbladder_2,
      3: params_gallbladder_3,
      4: measureData_gallbladder,
    };

    params_pancreas = {
      0: params_pancreas_0,
      1: params_pancreas_1,
      2: params_pancreas_2,
      3: params_pancreas_3,
      4: measureData_pancreas,
    };

    params_spleen = {
      0: params_spleen_0,
      1: params_spleen_1,
      2: params_spleen_2,
      3: params_spleen_3,
      4: measureData_spleen,
    };
    if (record.magic2 == "liver") {
      params = {
        肝脏: params_liver,
        胆囊: params_gallbladder,
        胰腺: params_pancreas,
      };
    } else if (record.magic2 == "spleen") {
      params = {
        脾脏: params_spleen,
      };
    } else {
      params = {
        肝脏: params_liver,
        胆囊: params_gallbladder,
        胰腺: params_pancreas,
        脾脏: params_spleen,
      };
    }
    return params;
  }
}
export function timeDifference(time1, time2) {
  if (time1 && time2) {
    const start = moment(time1);
    const end = moment(time2);
    return end.diff(start, "seconds");
  } else {
    return "";
  }
}
// 定义导出函数
export function exportToExcel(params, fileName, type) {
  const workbook = XLSX.utils.book_new();

  // 遍历params中的每一项并创建对应的工作表
  Object.keys(params).forEach((key) => {
    const data = params[key];

    let sheetData = [];

    if (Array.isArray(data)) {
      // 获取每个对象的keys作为表头列
      const headers = Object.keys(data[0]);

      // 构建二维数组，每一行第一列是字段名称，之后的列是对应医生的字段值
      headers.forEach((header) => {
        let row = [header]; // 第一列是表头（字段名）
        data.forEach((item) => {
          row.push(item[header]); // 将每个对象中的字段值依次加入对应列
        });
        sheetData.push(row);
      });
    } else {
      // 对于非数组数据，处理为单个对象（例如 params[2], params[3]）
      const headers = Object.keys(data);
      headers.forEach((header) => {
        sheetData.push([header, data[header]]);
      });
    }

    // 生成工作表
    const worksheet = XLSX.utils.aoa_to_sheet(sheetData);
    // 如果有数据，设置列宽
    if (worksheet && sheetData[0] && sheetData[0].length > 0) {
      try {
        const columnWidths = Array(sheetData[0].length).fill({ wch: 40 });
        worksheet["!cols"] = columnWidths;
      } catch (error) {
        console.error("设置列宽时出错: ", error);
      }
    }
    const sheetName = getSheetNameByKey(key); // 根据 key 获取工作表名称
    XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
  });
  // 生成 Excel 文件并保存
  if (type == "xlsx") {
    const excelBuffer = XLSX.write(workbook, {
      bookType: "xlsx",
      type: "array",
    });
    const blob = new Blob([excelBuffer], { type: "application/octet-stream" });
    saveAs(blob, `${fileName}.xlsx`);
  } else {
    const excelBuffer = XLSX.write(workbook, {
      bookType: "xlsx",
      type: "array",
    });
    const blob = new Blob([excelBuffer], {
      type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    });
    return blob;
  }
}
// 带有图片的导出方法
export async function exportToExcel2(params, fileName, type) {
  const workbook = new ExcelJS.Workbook();

  // 遍历 params 中的每一项并创建对应的工作表
  for (const key of Object.keys(params)) {
    const data = params[key];

    // 当 key == 2 时，加载模板文件并进行修改
    if (key == 2) {
      // 通过 fetch 请求加载模板文件
      const templateResponse = await fetch("/template.xlsx"); // 模板文件路径
      const templateArrayBuffer = await templateResponse.arrayBuffer();

      // 加载模板文件
      await workbook.xlsx.load(templateArrayBuffer);

      // 假设模板有一个已经存在的工作表，例如第一个工作表
      const templateWorksheet = workbook.getWorksheet(1);

      // 在模板的基础上添加数据
      const headers = Object.keys(data);
      headers.forEach((header, index) => {
        templateWorksheet.getCell(`A${index + 2}`).value = header; // 假设从A2开始
        templateWorksheet.getCell(`B${index + 2}`).value = data[header]; // 将数据写入B列
      });

      // 你可以根据需求在模板上添加更多内容
    } else {
      // 处理其他 key 的数据（例如 key == 0, 1, 3, 4）
      const worksheet = workbook.addWorksheet(getSheetNameByKey(key)); // 创建新工作表

      if (Array.isArray(data)) {
        const headers = Object.keys(data[0]);
        headers.forEach((header) => {
          const row = [header];
          data.forEach((item) => {
            row.push(item[header]); // 将每个对象中的字段值依次加入对应列
          });
          worksheet.addRow(row); // 添加数据行
        });
      } else {
        const headers = Object.keys(data);
        headers.forEach((header) => {
          worksheet.addRow([header, data[header] || ""]);
        });
      }

      // 设置列宽
      if (worksheet.rowCount > 0) {
        const columnWidths = Array(worksheet.getRow(1).cellCount).fill(40);
        columnWidths.forEach((width, index) => {
          worksheet.getColumn(index + 1).width = width;
        });
      }
    }
  }

  // 保存修改后的文件
  if (type === "xlsx") {
    const buffer = await workbook.xlsx.writeBuffer();
    const blob = new Blob([buffer], { type: "application/octet-stream" });
    saveAs(blob, `${fileName}.xlsx`);
  } else {
    const buffer = await workbook.xlsx.writeBuffer();
    const blob = new Blob([buffer], {
      type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    });
    return blob;
  }
}
// 根据 key 获取工作表名称
function getSheetNameByKey(key) {
  const sheetNames = {
    0: "扫查影像合格率-专家组",
    1: "标准切面识别率",
    2: "扫查影像合格率-对照医生",
    3: "试验器械诊断一致性",
    4: "检查时间与测量",
  };
  return sheetNames[key] || `Sheet${key}`;
}
export function delay(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}
//
export function dellDataByForms(recordsInfo) {
  try {
    let res_1 = {};
    let res_2 = {};
    let res_3 = {};
    let res_4 = {};
    let res_5 = {};

    let artery_1 = {};
    let artery_2 = {};
    let artery_3 = {};
    let artery_4 = {};
    let artery_5 = {};

    let thyroid_1 = {};
    let thyroid_2 = {};
    let thyroid_3 = {};
    let thyroid_4 = {};
    let thyroid_5 = {};

    let kidney_1 = {};
    let kidney_2 = {};
    let kidney_3 = {};
    let kidney_4 = {};
    let kidney_5 = {};

    let liver_1 = {};
    let liver_2 = {};
    let liver_3 = {};
    let liver_4 = {};
    let liver_5 = {};

    let gallbladder_1 = {};
    let gallbladder_2 = {};
    let gallbladder_3 = {};
    let gallbladder_4 = {};
    let gallbladder_5 = {};

    let pancreas_1 = {};
    let pancreas_2 = {};
    let pancreas_3 = {};
    let pancreas_4 = {};
    let pancreas_5 = {};

    let spleen_1 = {};
    let spleen_2 = {};
    let spleen_3 = {};
    let spleen_4 = {};
    let spleen_5 = {};
    let posInfo = {
      颈动脉: "artery_magic6",
      甲状腺: "thyroid_magic6",
      泌尿: "kidney_magic6",
    };

    if (recordsInfo.length == 0 || !recordsInfo) {
      return;
    }
    recordsInfo.forEach((item) => {
      let { forms, measureInfo, pos, startAt, endAt, magic2, magic6, sNo } =
        item;
      res_1["sNo"] = sNo;
      res_2["sNo"] = sNo;
      res_3["sNo"] = sNo;
      res_4["sNo"] = sNo;
      res_5["sNo"] = sNo;
      if (pos == "腹部") {
        if (magic2 == "liver") {
          res_1["liver_magic6"] = magic6;
          res_2["liver_magic6"] = magic6;
          res_3["liver_magic6"] = magic6;
          res_4["liver_magic6"] = magic6;
          res_5["liver_magic6"] = magic6;
        } else {
          res_1["spleen_magic6"] = magic6;
          res_2["spleen_magic6"] = magic6;
          res_3["spleen_magic6"] = magic6;
          res_4["spleen_magic6"] = magic6;
          res_5["spleen_magic6"] = magic6;
        }
      } else {
        const name = posInfo[pos];
        res_1[name] = magic6;
        res_2[name] = magic6;
        res_3[name] = magic6;
        res_4[name] = magic6;
        res_5[name] = magic6;
      }
      if (forms.length > 0) {
        // forms = forms.sort((a,b)=>{
        //   if(a.level == 7 && b.level != 7 ) return -1;
        //   if(a.level != 7 && b.level == 7 ) return 1;
        //   if(a.level == 6 && b.level == 6){
        //     if(a.evaluationResult && b.evaluationResult){
        //       return new Date(a.finishDate) - new Date(b.finishDate);
        //     }
        //     if(a.evaluationResult && !b.evaluationResult) return  -1;
        //     if(!a.evaluationResult && b.evaluationResult) return  1;
        //   }
        //   return 0;
        // });
        forms.forEach((item) => {
          if (item.evaluationResult) {
            const evaluationResult = JSON.parse(item.evaluationResult);
            if (item.evaluationID == 0 && item.level == 6) {
              // console.log(evaluationResult)
              // console.log(`有 evaluationResult 扫查影像评价表-专家 name:${item.doctorName},pos:${item.pos}`);
              if (item.pos == "颈动脉") {
                artery_1[item.doctorName] = {
                  artery_completeness: evaluationResult[item.pos]["扫查完整性"],
                  artery_intima: evaluationResult[item.pos]["左侧内膜"],
                  artery_filling:
                    evaluationResult[item.pos]["左侧血流充盈程度"],
                  artery_brightness: evaluationResult[item.pos]["左侧彩色亮度"],
                  artery_distribution:
                    evaluationResult[item.pos]["左侧色彩分布"],
                  artery_edge: evaluationResult[item.pos]["左侧频谱-边缘"],
                  artery_definition:
                    evaluationResult[item.pos]["左侧频谱-清晰度"],
                  artery_shape: evaluationResult[item.pos]["左侧频谱-形态"],
                  artery_intima_right: evaluationResult[item.pos]["右侧内膜"],
                  artery_filling_right:
                    evaluationResult[item.pos]["右侧血流充盈程度"],
                  artery_brightness_right:
                    evaluationResult[item.pos]["右侧彩色亮度"],
                  artery_distribution_right:
                    evaluationResult[item.pos]["右侧色彩分布"],
                  artery_edge_right:
                    evaluationResult[item.pos]["右侧频谱-边缘"],
                  artery_definition_right:
                    evaluationResult[item.pos]["右侧频谱-清晰度"],
                  artery_shape_right:
                    evaluationResult[item.pos]["右侧频谱-形态"],
                  artery_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "甲状腺") {
                thyroid_1[item.doctorName] = {
                  thyroid_completeness:
                    evaluationResult[item.pos]["扫查完整性"],
                  thyroid_shape: evaluationResult[item.pos]["形态轮廓"],
                  thyroid_detailLevel: evaluationResult[item.pos]["细腻程度"],
                  thyroid_brightness: evaluationResult[item.pos]["彩色亮度"],
                  thyroid_distribution: evaluationResult[item.pos]["色彩分布"],
                  thyroid_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "泌尿") {
                kidney_1[item.doctorName] = {
                  kidney_completeness: evaluationResult[item.pos]["扫查完整性"],
                  kidney_shape: evaluationResult[item.pos]["左肾形态轮廓"],
                  kidney_cortex:
                    evaluationResult[item.pos]["左肾皮质、髓质显示"],
                  kidney_brightness: evaluationResult[item.pos]["左肾彩色亮度"],
                  kidney_distribution:
                    evaluationResult[item.pos]["左肾色彩分布"],
                  kidney_shape_right:
                    evaluationResult[item.pos]["右肾形态轮廓"],
                  kidney_cortex_right:
                    evaluationResult[item.pos]["右肾皮质、髓质显示"],
                  kidney_brightness_right:
                    evaluationResult[item.pos]["右肾彩色亮度"],
                  kidney_distribution_right:
                    evaluationResult[item.pos]["右肾色彩分布"],
                  kidney_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "腹部") {
                const liverRes = evaluationResult["肝脏"];
                const gallbladderRes = evaluationResult["胆囊"];
                const pancreasRes = evaluationResult["胰腺"];
                const spleenRes = evaluationResult["脾脏"];
                if (magic2 == "liver") {
                  liver_1[item.doctorName] = {
                    liver_completeness_q: liverRes["扫查完整性"],
                    liver_shape_q: liverRes["形态轮廓"],
                    liver_structure_q: liverRes["管道结构"],
                    liver_detailLevel_q: liverRes["细腻程度"],
                    liver_brightness_q: liverRes["彩色亮度"],
                    liver_distribution_q: liverRes["色彩分布"],
                    liver_filling_q: liverRes["血管充盈度"],
                    liver_finishDate: moment(item.finishDate).valueOf(),
                  };
                  gallbladder_1[item.doctorName] = {
                    gallbladder_completeness_q: gallbladderRes["扫查完整性"],
                    gallbladder_wall_q: gallbladderRes["胆囊壁"],
                    gallbladder_cavity_q: gallbladderRes["胆囊腔"],
                    gallbladder_finishDate: moment(item.finishDate).valueOf(),
                  };
                  pancreas_1[item.doctorName] = {
                    pancreas_completeness_q: pancreasRes["扫查完整性"],
                    pancreas_shape_q: pancreasRes["形态轮廓"],
                    pancreas_detailLevel_q: pancreasRes["细腻程度"],
                    pancreas_finishDate: moment(item.finishDate).valueOf(),
                  };
                } else {
                  spleen_1[item.doctorName] = {
                    spleen_completeness_q: spleenRes["扫查完整性"],
                    spleen_shape_q: spleenRes["形态轮廓"],
                    spleen_detailLevel_q: spleenRes["细腻程度"],
                    spleen_blood_q: spleenRes["脾门血管"],
                    spleen_finishDate: moment(item.finishDate).valueOf(),
                  };
                }
              }
            } else if (item.evaluationID == 1 && item.level == 6) {
              // console.log(evaluationResult)
              // console.log(`有 标准切面质量评价表-专家组,name:${item.doctorName},pos:${item.pos}`);
              if (item.pos == "颈动脉") {
                artery_2[item.doctorName] = {
                  LeftCrossCCA:
                    evaluationResult[item.pos]["左侧颈总动脉横切面"],
                  LeftCrossBifurcation:
                    evaluationResult[item.pos]["左侧窦部横切面"],
                  LeftCrossICAECA:
                    evaluationResult[item.pos]["左侧颈内及颈外动脉横切面"],
                  LeftLongCCA:
                    evaluationResult[item.pos]["左侧颈内及颈外动脉纵切面"],
                  LeftLongICA: evaluationResult[item.pos]["左侧颈总动脉纵切面"],
                  LeftLongCCAStartSeg:
                    evaluationResult[item.pos]["左侧颈总动脉起始部纵切面"],
                  rightCrossCCA:
                    evaluationResult[item.pos]["右侧颈总动脉横切面"],
                  rightCrossBifurcation:
                    evaluationResult[item.pos]["右侧窦部横切面"],
                  rightCrossICAECA:
                    evaluationResult[item.pos]["右侧颈内及颈外动脉横切面"],
                  rightLongCCA:
                    evaluationResult[item.pos]["右侧颈内及颈外动脉纵切面"],
                  rightLongICA:
                    evaluationResult[item.pos]["右侧颈总动脉纵切面"],
                  rightLongCCAStartSeg:
                    evaluationResult[item.pos]["右侧颈总动脉起始部纵切面"],
                  artery_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "甲状腺") {
                thyroid_2[item.doctorName] = {
                  crossThmus: evaluationResult[item.pos]["峡部横切面"],
                  crossLeftLobe: evaluationResult[item.pos]["左侧叶横切面"],
                  LongLeftLobe: evaluationResult[item.pos]["左侧叶纵切面"],
                  crossRightLobe: evaluationResult[item.pos]["右侧叶横切面"],
                  LongRIghtLobe: evaluationResult[item.pos]["右侧叶纵切面"],
                  thyroid_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "泌尿") {
                kidney_2[item.doctorName] = {
                  kidney1: evaluationResult[item.pos]["左肾脏的长轴切面"],
                  kidney2: evaluationResult[item.pos]["右肾脏的长轴切面"],
                  kidney_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "腹部") {
                const liverRes = evaluationResult["肝脏"];
                const gallbladderRes = evaluationResult["胆囊"];
                const pancreasRes = evaluationResult["胰腺"];
                const spleenRes = evaluationResult["脾脏"];
                if (magic2 == "liver") {
                  liver_2[item.doctorName] = {
                    liver1: liverRes["肝左叶经腹主动脉长轴纵切面"],
                    liver2: liverRes["肝左叶斜切面"],
                    liver3: liverRes["肋下斜切第二肝门切面"],
                    liver4: liverRes["右肋下右肝及右肾纵切面"],
                    liver5: liverRes["右肋间经第一肝门斜切面"],
                    liver_finishDate: moment(item.finishDate).valueOf(),
                  };
                  gallbladder_2[item.doctorName] = {
                    gallbladder1: gallbladderRes["胆囊长轴纵切面"],
                    gallbladder_finishDate: moment(item.finishDate).valueOf(),
                  };
                  pancreas_2[item.doctorName] = {
                    pancreas1: pancreasRes["胰腺长轴切面"],
                    pancreas_finishDate: moment(item.finishDate).valueOf(),
                  };
                } else {
                  spleen_2[item.doctorName] = {
                    spleen1: spleenRes["脾脏纵切面"],
                    spleen_finishDate: moment(item.finishDate).valueOf(),
                  };
                }
              }
            } else if (item.evaluationID == 0 && item.level == 7) {
              // console.log(evaluationResult)
              // console.log(`有 扫查影像评价表-对照医生 ,name:${item.doctorName},pos:${item.pos}`);
              if (item.pos == "颈动脉") {
                artery_3 = {
                  artery_completeness: evaluationResult[item.pos]["扫查完整性"],
                  artery_intima: evaluationResult[item.pos]["左侧内膜"],
                  artery_filling:
                    evaluationResult[item.pos]["左侧血流充盈程度"],
                  artery_brightness: evaluationResult[item.pos]["左侧彩色亮度"],
                  artery_distribution:
                    evaluationResult[item.pos]["左侧色彩分布"],
                  artery_edge: evaluationResult[item.pos]["左侧频谱-边缘"],
                  artery_definition:
                    evaluationResult[item.pos]["左侧频谱-清晰度"],
                  artery_shape: evaluationResult[item.pos]["左侧频谱-形态"],
                  artery_intima_right: evaluationResult[item.pos]["右侧内膜"],
                  artery_filling_right:
                    evaluationResult[item.pos]["右侧血流充盈程度"],
                  artery_brightness_right:
                    evaluationResult[item.pos]["右侧彩色亮度"],
                  artery_distribution_right:
                    evaluationResult[item.pos]["右侧色彩分布"],
                  artery_edge_right:
                    evaluationResult[item.pos]["右侧频谱-边缘"],
                  artery_definition_right:
                    evaluationResult[item.pos]["右侧频谱-清晰度"],
                  artery_shape_right:
                    evaluationResult[item.pos]["右侧频谱-形态"],
                  artery_finishDate: moment(item.finishDate).format(
                    "YYYY年MM月DD日"
                  ),
                };
              } else if (item.pos == "甲状腺") {
                thyroid_3 = {
                  thyroid_completeness:
                    evaluationResult[item.pos]["扫查完整性"],
                  thyroid_shape: evaluationResult[item.pos]["形态轮廓"],
                  thyroid_detailLevel: evaluationResult[item.pos]["细腻程度"],
                  thyroid_brightness: evaluationResult[item.pos]["彩色亮度"],
                  thyroid_distribution: evaluationResult[item.pos]["色彩分布"],
                  thyroid_finishDate: moment(item.finishDate).format(
                    "YYYY年MM月DD日"
                  ),
                };
              } else if (item.pos == "泌尿") {
                kidney_3 = {
                  kidney_completeness: evaluationResult[item.pos]["扫查完整性"],
                  kidney_shape: evaluationResult[item.pos]["左肾形态轮廓"],
                  kidney_cortex:
                    evaluationResult[item.pos]["左肾皮质、髓质显示"],
                  kidney_brightness: evaluationResult[item.pos]["左肾彩色亮度"],
                  kidney_distribution:
                    evaluationResult[item.pos]["左肾色彩分布"],
                  kidney_shape_right:
                    evaluationResult[item.pos]["右肾形态轮廓"],
                  kidney_cortex_right:
                    evaluationResult[item.pos]["右肾皮质、髓质显示"],
                  kidney_brightness_right:
                    evaluationResult[item.pos]["右肾彩色亮度"],
                  kidney_distribution_right:
                    evaluationResult[item.pos]["右肾色彩分布"],
                  kidney_finishDate: moment(item.finishDate).format(
                    "YYYY年MM月DD日"
                  ),
                };
              } else if (item.pos == "腹部") {
                const liverRes = evaluationResult["肝脏"];
                const gallbladderRes = evaluationResult["胆囊"];
                const pancreasRes = evaluationResult["胰腺"];
                const spleenRes = evaluationResult["脾脏"];
                if (magic2 == "liver") {
                  liver_3 = {
                    liver_completeness: liverRes["扫查完整性"],
                    liver_shape: liverRes["形态轮廓"],
                    liver_structure: liverRes["管道结构"],
                    liver_detailLevel: liverRes["细腻程度"],
                    liver_brightness: liverRes["彩色亮度"],
                    liver_distribution: liverRes["色彩分布"],
                    liver_filling: liverRes["血管充盈度"],
                    liver_finishDate: moment(item.finishDate).format(
                      "YYYY年MM月DD日"
                    ),
                  };
                  gallbladder_3 = {
                    gallbladder_completeness: gallbladderRes["扫查完整性"],
                    gallbladder_wall: gallbladderRes["胆囊壁"],
                    gallbladder_cavity: gallbladderRes["胆囊腔"],
                    gallbladder_finishDate: moment(item.finishDate).format(
                      "YYYY年MM月DD日"
                    ),
                  };
                  pancreas_3 = {
                    pancreas_completeness: pancreasRes["扫查完整性"],
                    pancreas_shape: pancreasRes["形态轮廓"],
                    pancreas_detailLevel: pancreasRes["细腻程度"],
                    pancreas_finishDate: moment(item.finishDate).format(
                      "YYYY年MM月DD日"
                    ),
                  };
                } else {
                  spleen_3 = {
                    spleen_completeness: spleenRes["扫查完整性"],
                    spleen_shape: spleenRes["形态轮廓"],
                    spleen_detailLevel: spleenRes["细腻程度"],
                    spleen_blood: spleenRes["脾门血管"],
                    spleen_finishDate: moment(item.finishDate).format(
                      "YYYY年MM月DD日"
                    ),
                  };
                }
              }
            } else if (item.evaluationID == 2 && item.level == 7) {
              // console.log(evaluationResult)
              // console.log(`有 试验器械诊断表-对照医生 ,name${item.doctorName},pos:${item.pos}`);
              if (item.pos == "颈动脉") {
                artery_4 = {
                  artery_sonogram_left:
                    evaluationResult[item.pos]["左侧声像图"],
                  artery_plaque_left: evaluationResult[item.pos]["左侧斑块"],
                  artery_blood_left: evaluationResult[item.pos]["左侧血管闭塞"],
                  artery_sonogram_right:
                    evaluationResult[item.pos]["右侧声像图"],
                  artery_plaque_right: evaluationResult[item.pos]["右侧斑块"],
                  artery_blood_right:
                    evaluationResult[item.pos]["右侧血管闭塞"],
                  artery_finishDate: moment(item.finishDate).format(
                    "YYYY年MM月DD日"
                  ),
                };
              } else if (item.pos == "甲状腺") {
                thyroid_4 = {
                  thyroid_sonogram: evaluationResult[item.pos]["声像图"],
                  thyroid_diffuse: evaluationResult[item.pos]["弥漫性异常"],
                  thyroid_echoes: evaluationResult[item.pos]["实质性回声"],
                  thyroid_localized_echo:
                    evaluationResult[item.pos]["局限性异常回声"],
                  thyroid_echo_strength:
                    evaluationResult[item.pos]["局限性异常回声强度"],
                  thyroid_echo_shape:
                    evaluationResult[item.pos]["局限性异常回声形态"],
                  thyroid_finishDate: moment(item.finishDate).format(
                    "YYYY年MM月DD日"
                  ),
                };
              } else if (item.pos == "泌尿") {
                kidney_4 = {
                  kidney_sonogram_left:
                    evaluationResult[item.pos]["左肾声像图"],
                  kidney_echoes_left:
                    evaluationResult[item.pos]["左肾实质性回声"],
                  kidney_localized_echo_left:
                    evaluationResult[item.pos]["左肾局限性异常回声"],
                  kidney_echo_strength_left:
                    evaluationResult[item.pos]["左肾局限性异常回声强度"],
                  kidney_echo_shape_left:
                    evaluationResult[item.pos]["左肾局限性异常回声形态"],
                  kidney_sonogram_right:
                    evaluationResult[item.pos]["右肾声像图"],
                  kidney_echoes_right:
                    evaluationResult[item.pos]["右肾实质性回声"],
                  kidney_localized_echo_right:
                    evaluationResult[item.pos]["右肾局限性异常回声"],
                  kidney_echo_strength_right:
                    evaluationResult[item.pos]["右肾局限性异常回声强度"],
                  kidney_echo_shape_right:
                    evaluationResult[item.pos]["右肾局限性异常回声形态"],
                  kidney_finishDate: moment(item.finishDate).format(
                    "YYYY年MM月DD日"
                  ),
                };
              } else if (item.pos == "腹部") {
                const liverRes = evaluationResult["肝脏"];
                const gallbladderRes = evaluationResult["胆囊"];
                const pancreasRes = evaluationResult["胰腺"];
                const spleenRes = evaluationResult["脾脏"];
                if (magic2 == "liver") {
                  liver_4 = {
                    liver_sonogram: liverRes["声像图"],
                    liver_diffuse: liverRes["肝实质回声弥漫性增强"],
                    liver_echoes: liverRes["实质性回声"],
                    liver_localized_echo: liverRes["局限性异常回声"],
                    liver_echo_strength: liverRes["局限性异常回声强度"],
                    liver_echo_shape: liverRes["局限性异常回声形态"],
                    liver_finishDate: moment(item.finishDate).format(
                      "YYYY年MM月DD日"
                    ),
                  };
                  gallbladder_4 = {
                    gallbladder_sonogram: gallbladderRes["声像图"],
                    gallbladder_wall: gallbladderRes["胆囊壁异常"],
                    gallbladder_echoes: gallbladderRes["胆囊腔异常回声"],
                    gallbladder_finishDate: moment(item.finishDate).format(
                      "YYYY年MM月DD日"
                    ),
                  };
                  pancreas_4 = {
                    pancreas_sonogram: pancreasRes["声像图"],
                    pancreas_echoes: pancreasRes["实质性回声"],
                    pancreas_localized_echo: pancreasRes["局限性异常回声"],
                    pancreas_echo_strength: pancreasRes["局限性异常回声强度"],
                    pancreas_echo_shape: pancreasRes["局限性异常回声形态"],
                    pancreas_finishDate: moment(item.finishDate).format(
                      "YYYY年MM月DD日"
                    ),
                  };
                } else {
                  spleen_4 = {
                    spleen_sonogram: spleenRes["声像图"],
                    spleen_echoes: spleenRes["实质性回声"],
                    spleen_localized_echo: spleenRes["局限性异常回声"],
                    spleen_echo_strength: spleenRes["局限性异常回声强度"],
                    spleen_echo_shape: spleenRes["局限性异常回声形态"],
                    spleen_finishDate: moment(item.finishDate).format(
                      "YYYY年MM月DD日"
                    ),
                  };
                }
              }
            }
          } else {
            if (item.evaluationID == 0 && item.level == 6) {
              // console.log("无 扫查影像评价表-专家",item.doctorName);
              if (item.pos == "颈动脉") {
                artery_1[item.doctorName] = {
                  artery_completeness: "",
                  artery_intima: "",
                  artery_filling: "",
                  artery_brightness: "",
                  artery_distribution: "",
                  artery_edge: "",
                  artery_definition: "",
                  artery_shape: "",
                  artery_intima_right: "",
                  artery_filling_right: "",
                  artery_brightness_right: "",
                  artery_distribution_right: "",
                  artery_edge_right: "",
                  artery_definition_right: "",
                  artery_shape_right: "",
                  artery_finishDate: "",
                };
              } else if (item.pos == "甲状腺") {
                thyroid_1[item.doctorName] = {
                  thyroid_completeness: "",
                  thyroid_shape: "",
                  thyroid_detailLevel: "",
                  thyroid_brightness: "",
                  thyroid_distribution: "",
                  thyroid_finishDate: "",
                };
              } else if (item.pos == "泌尿") {
                kidney_1[item.doctorName] = {
                  kidney_completeness: "",
                  kidney_shape: "",
                  kidney_cortex: "",
                  kidney_brightness: "",
                  kidney_distribution: "",
                  kidney_shape_right: "",
                  kidney_cortex_right: "",
                  kidney_brightness_right: "",
                  kidney_distribution_right: "",
                  kidney_finishDate: "",
                };
              } else if (item.pos == "腹部") {
                if (magic2 == "liver") {
                  liver_1[item.doctorName] = {
                    liver_completeness_q: "",
                    liver_shape_q: "",
                    liver_structure_q: "",
                    liver_detailLevel_q: "",
                    liver_brightness_q: "",
                    liver_distribution_q: "",
                    liver_filling_q: "",
                    liver_finishDate: "",
                  };
                  gallbladder_1[item.doctorName] = {
                    gallbladder_completeness_q: "",
                    gallbladder_wall_q: "",
                    gallbladder_cavity_q: "",
                    gallbladder_finishDate: "",
                  };
                  pancreas_1[item.doctorName] = {
                    pancreas_completeness_q: "",
                    pancreas_shape_q: "",
                    pancreas_detailLevel_q: "",
                    pancreas_finishDate: "",
                  };
                } else {
                  spleen_1[item.doctorName] = {
                    spleen_completeness_q: "",
                    spleen_shape_q: "",
                    spleen_detailLevel_q: "",
                    spleen_blood_q: "",
                    spleen_finishDate: "",
                  };
                }
              }
            } else if (item.evaluationID == 1 && item.level == 6) {
              // console.log("无 标准切面质量评价表-专家组",item.doctorName);
              if (item.pos == "颈动脉") {
                artery_2[item.doctorName] = {
                  LeftCrossCCA: "",
                  LeftCrossBifurcation: "",
                  LeftCrossICAECA: "",
                  LeftLongCCA: "",
                  LeftLongICA: "",
                  LeftLongCCAStartSeg: "",
                  rightCrossCCA: "",
                  rightCrossBifurcation: "",
                  rightCrossICAECA: "",
                  rightLongCCA: "",
                  rightLongICA: "",
                  rightLongCCAStartSeg: "",
                  artery_finishDate: "",
                };
              } else if (item.pos == "甲状腺") {
                thyroid_2[item.doctorName] = {
                  crossThmus: "",
                  crossLeftLobe: "",
                  LongLeftLobe: "",
                  crossRightLobe: "",
                  LongRIghtLobe: "",
                  thyroid_finishDate: "",
                };
              } else if (item.pos == "泌尿") {
                kidney_2[item.doctorName] = {
                  kidney1: "",
                  kidney2: "",
                  kidney_finishDate: "",
                };
              } else if (item.pos == "腹部") {
                if (magic2 == "liver") {
                  liver_2[item.doctorName] = {
                    liver1: "",
                    liver2: "",
                    liver3: "",
                    liver4: "",
                    liver5: "",
                    liver_finishDate: "",
                  };
                  gallbladder_2[item.doctorName] = {
                    gallbladder1: "",
                    gallbladder_finishDate: "",
                  };
                  pancreas_2[item.doctorName] = {
                    pancreas1: "",
                    pancreas_finishDate: "",
                  };
                } else {
                  spleen_2[item.doctorName] = {
                    spleen1: "",
                    spleen_finishDate: "",
                  };
                }
              }
            } else if (item.evaluationID == 0 && item.level == 7) {
              // console.log("无 扫查影像评价表-对照医生",item.doctorName);
              if (item.pos == "颈动脉") {
                artery_3 = {
                  artery_completeness: "",
                  artery_intima: "",
                  artery_filling: "",
                  artery_brightness: "",
                  artery_distribution: "",
                  artery_edge: "",
                  artery_definition: "",
                  artery_shape: "",
                  artery_intima_right: "",
                  artery_filling_right: "",
                  artery_brightness_right: "",
                  artery_distribution_right: "",
                  artery_edge_right: "",
                  artery_definition_right: "",
                  artery_shape_right: "",
                  artery_finishDate: "",
                };
              } else if (item.pos == "甲状腺") {
                thyroid_3 = {
                  thyroid_completeness: "",
                  thyroid_shape: "",
                  thyroid_detailLevel: "",
                  thyroid_brightness: "",
                  thyroid_distribution: "",
                  thyroid_finishDate: "",
                };
              } else if (item.pos == "泌尿") {
                kidney_3 = {
                  kidney_completeness: "",
                  kidney_shape: "",
                  kidney_cortex: "",
                  kidney_brightness: "",
                  kidney_distribution: "",
                  kidney_shape_right: "",
                  kidney_cortex_right: "",
                  kidney_brightness_right: "",
                  kidney_distribution_right: "",
                  kidney_finishDate: "",
                };
              } else if (item.pos == "腹部") {
                if (magic2 == "liver") {
                  liver_3 = {
                    liver_completeness: "",
                    liver_shape: "",
                    liver_structure: "",
                    liver_detailLevel: "",
                    liver_brightness: "",
                    liver_distribution: "",
                    liver_filling: "",
                    liver_finishDate: "",
                  };
                  gallbladder_3 = {
                    gallbladder_completeness: "",
                    gallbladder_wall: "",
                    gallbladder_cavity: "",
                    gallbladder_finishDate: "",
                  };
                  pancreas_3 = {
                    pancreas_completeness: "",
                    pancreas_shape: "",
                    pancreas_detailLevel: "",
                    pancreas_finishDate: "",
                  };
                } else {
                  spleen_3 = {
                    spleen_completeness: "",
                    spleen_shape: "",
                    spleen_detailLevel: "",
                    spleen_blood: "",
                    spleen_finishDate: "",
                  };
                }
              }
            } else if (item.evaluationID == 2 && item.level == 7) {
              // console.log("无 试验器械诊断表",item.doctorName);
              if (item.pos == "颈动脉") {
                artery_4 = {
                  artery_sonogram_left: "",
                  artery_plaque_left: "",
                  artery_blood_left: "",
                  artery_sonogram_right: "",
                  artery_plaque_right: "",
                  artery_blood_right: "",
                  artery_finishDate: "",
                };
              } else if (item.pos == "甲状腺") {
                thyroid_4 = {
                  thyroid_sonogram: "",
                  thyroid_diffuse: "",
                  thyroid_echoes: "",
                  thyroid_localized_echo: "",
                  thyroid_echo_strength: "",
                  thyroid_echo_shape: "",
                  thyroid_finishDate: "",
                };
              } else if (item.pos == "泌尿") {
                kidney_4 = {
                  kidney_sonogram_left: "",
                  kidney_echoes_left: "",
                  kidney_localized_echo_left: "",
                  kidney_echo_strength_left: "",
                  kidney_echo_shape_left: "",
                  kidney_sonogram_right: "",
                  kidney_echoes_right: "",
                  kidney_localized_echo_right: "",
                  kidney_echo_strength_right: "",
                  kidney_echo_shape_right: "",
                  kidney_finishDate: "",
                };
              } else if (item.pos == "腹部") {
                if (magic2 == "liver") {
                  liver_4 = {
                    liver_sonogram: "",
                    liver_diffuse: "",
                    liver_echoes: "",
                    liver_localized_echo: "",
                    liver_echo_strength: "",
                    liver_echo_shape: "",
                    liver_finishDate: "",
                  };
                  gallbladder_4 = {
                    gallbladder_sonogram: "",
                    gallbladder_wall: "",
                    gallbladder_echoes: "",
                    gallbladder_finishDate: "",
                  };
                  pancreas_4 = {
                    pancreas_sonogram: "",
                    pancreas_echoes: "",
                    pancreas_localized_echo: "",
                    pancreas_echo_strength: "",
                    pancreas_echo_shape: "",
                    pancreas_finishDate: "",
                  };
                } else {
                  spleen_4 = {
                    spleen_sonogram: "",
                    spleen_echoes: "",
                    spleen_localized_echo: "",
                    spleen_echo_strength: "",
                    spleen_echo_shape: "",
                    spleen_finishDate: "",
                  };
                }
              }
            }
          }
        });
      }
      if (measureInfo) {
        measureInfo = JSON.parse(measureInfo);
        // console.log("measureInfo",measureInfo)
        if (pos == "颈动脉") {
          const scanIMTInfo = measureInfo.scanIMTInfo;
          const vesselDiameterInfo = measureInfo.vesselDiameterInfo;
          const psedInfo = measureInfo.psedInfo;
          const left_psedInfo = psedInfo ? psedInfo[2] : "";
          const right_psedInfo = psedInfo ? psedInfo[4] : "";
          const left_psedInfo_1 = left_psedInfo
            ? left_psedInfo.split("/")[0]
            : "";
          const left_psedInfo_2 = left_psedInfo
            ? left_psedInfo.split("/")[1]
            : "";
          const left_psedInfo_3 = right_psedInfo
            ? right_psedInfo.split("/")[0]
            : "";
          const left_psedInfo_4 = right_psedInfo
            ? right_psedInfo.split("/")[1]
            : "";
          artery_5 = {
            artery_dateTime: moment(startAt).format("YYYY年MM月DD日"),
            artery_startAt: moment(startAt).format("HH时mm分ss秒"),
            artery_endAt: moment(endAt).format("HH时mm分ss秒"),
            artery_total: timeDifference(startAt, endAt),
            vesselDiameterInfo19: vesselDiameterInfo[19]
              ? vesselDiameterInfo[19]
              : "",
            scanIMTInfo19: scanIMTInfo[19] ? scanIMTInfo[19] : "",
            left_psedInfo_1: left_psedInfo_1,
            left_psedInfo_2: left_psedInfo_2,
            vesselDiameterInfo33: vesselDiameterInfo[33]
              ? vesselDiameterInfo[33]
              : "",
            scanIMTInfo33: scanIMTInfo[33] ? scanIMTInfo[33] : "",
            left_psedInfo_3: left_psedInfo_3,
            left_psedInfo_4: left_psedInfo_4,
          };
        } else if (pos == "甲状腺") {
          const thyroid_measure = measureInfo.thyroid_measure;
          thyroid_5 = {
            thyroid_dateTime: moment(startAt).format("YYYY年MM月DD日"),
            thyroid_startAt: moment(startAt).format("HH时mm分ss秒"),
            thyroid_endAt: moment(endAt).format("HH时mm分ss秒"),
            thyroid_total: timeDifference(startAt, endAt),
            thyroid_measure0: thyroid_measure[0] ? thyroid_measure[0] * 10 : "",
            thyroid_measure1: thyroid_measure[1] ? thyroid_measure[1] * 10 : "",
            thyroid_measure2: thyroid_measure[2] ? thyroid_measure[2] * 10 : "",
            thyroid_measure3: thyroid_measure[3] ? thyroid_measure[3] * 10 : "",
            thyroid_measure4: thyroid_measure[4] ? thyroid_measure[4] * 10 : "",
            thyroid_measure5: thyroid_measure[5] ? thyroid_measure[5] * 10 : "",
            thyroid_measure6: thyroid_measure[6] ? thyroid_measure[6] * 10 : "",
          };
        } else if (pos == "泌尿" || pos == "肾脏") {
          const urinaryMeasure = measureInfo.urinaryMeasure;
          kidney_5 = {
            kidney_dateTime: moment(startAt).format("YYYY年MM月DD日"),
            kidney_startAt: moment(startAt).format("HH时mm分ss秒"),
            kidney_endAt: moment(endAt).format("HH时mm分ss秒"),
            kidney_total: timeDifference(startAt, endAt),
            urinaryMeasure5011: urinaryMeasure[5011]
              ? urinaryMeasure[5011] * 10
              : "",
            urinaryMeasure5012: urinaryMeasure[5012]
              ? urinaryMeasure[5012] * 10
              : "",
            urinaryMeasure5021: urinaryMeasure[5021]
              ? urinaryMeasure[5021] * 10
              : "",
            urinaryMeasure5022: urinaryMeasure[5022]
              ? urinaryMeasure[5022] * 10
              : "",
          };
        } else if (pos == "腹部") {
          const digestiveMeasure = measureInfo.digestiveMeasure;
          const spleenMeasure = measureInfo.spleenMeasure;
          if (magic2 == "liver") {
            liver_5 = {
              liver_dateTime: moment(startAt).format("YYYY年MM月DD日"),
              liver_startAt: moment(startAt).format("HH时mm分ss秒"),
              liver_endAt: moment(endAt).format("HH时mm分ss秒"),
              liver_total: timeDifference(startAt, endAt),
              digestiveMeasure3011: digestiveMeasure[3011]
                ? digestiveMeasure[3011] * 10
                : "",
              digestiveMeasure3012: digestiveMeasure[3012]
                ? digestiveMeasure[3012] * 10
                : "",
              digestiveMeasure3021: digestiveMeasure[3021]
                ? digestiveMeasure[3021] * 10
                : "",
              digestiveMeasure3051: digestiveMeasure[3051]
                ? digestiveMeasure[3051] * 10
                : "",
            };
            gallbladder_5 = {
              gallbladder_dateTime: moment(startAt).format("YYYY年MM月DD日"),
              gallbladder_startAt: moment(startAt).format("HH时mm分ss秒"),
              gallbladder_endAt: moment(endAt).format("HH时mm分ss秒"),
              gallbladder_total: timeDifference(startAt, endAt),
              digestiveMeasure3031: digestiveMeasure[3031]
                ? digestiveMeasure[3031] * 10
                : "",
              digestiveMeasure3032: digestiveMeasure[3032]
                ? digestiveMeasure[3032] * 10
                : "",
            };
            pancreas_5 = {
              pancreas_dateTime: moment(startAt).format("YYYY年MM月DD日"),
              pancreas_startAt: moment(startAt).format("HH时mm分ss秒"),
              pancreas_endAt: moment(endAt).format("HH时mm分ss秒"),
              pancreas_total: timeDifference(startAt, endAt),
              digestiveMeasure3061: digestiveMeasure[3061]
                ? digestiveMeasure[3061] * 10
                : "",
            };
          } else {
            spleen_5 = {
              spleen_dateTime: moment(startAt).format("YYYY年MM月DD日"),
              spleen_startAt: moment(startAt).format("HH时mm分ss秒"),
              spleen_endAt: moment(endAt).format("HH时mm分ss秒"),
              spleen_total: timeDifference(startAt, endAt),
              spleenMeasure4011: spleenMeasure[4011]
                ? spleenMeasure[4011] * 10
                : "",
              spleenMeasure4012: spleenMeasure[4012]
                ? spleenMeasure[4012] * 10
                : "",
              spleenMeasure4021: spleenMeasure[4021]
                ? spleenMeasure[4021] * 10
                : "",
            };
          }
        }
      } else {
        if (pos == "颈动脉") {
          artery_5 = {
            artery_dateTime: "",
            artery_startAt: "",
            artery_endAt: "",
            artery_total: "",
            vesselDiameterInfo19: "",
            scanIMTInfo19: "",
            left_psedInfo_1: "",
            left_psedInfo_2: "",
            vesselDiameterInfo33: "",
            scanIMTInfo33: "",
            left_psedInfo_3: "",
            left_psedInfo_4: "",
          };
        } else if (pos == "甲状腺") {
          thyroid_5 = {
            thyroid_dateTime: "",
            thyroid_startAt: "",
            thyroid_endAt: "",
            thyroid_total: "",
            thyroid_measure0: "",
            thyroid_measure1: "",
            thyroid_measure2: "",
            thyroid_measure3: "",
            thyroid_measure4: "",
            thyroid_measure5: "",
            thyroid_measure6: "",
          };
        } else if (pos == "泌尿" || pos == "肾脏") {
          kidney_5 = {
            kidney_dateTime: "",
            kidney_startAt: "",
            kidney_endAt: "",
            kidney_total: "",
            urinaryMeasure5011: "",
            urinaryMeasure5012: "",
            urinaryMeasure5021: "",
            urinaryMeasure5022: "",
          };
        } else if (pos == "腹部") {
          if (magic2 == "liver") {
            liver_5 = {
              liver_dateTime: "",
              liver_startAt: "",
              liver_endAt: "",
              liver_total: "",
              digestiveMeasure3011: "",
              digestiveMeasure3012: "",
              digestiveMeasure3021: "",
              digestiveMeasure3051: "",
            };
            gallbladder_5 = {
              gallbladder_dateTime: "",
              gallbladder_startAt: "",
              gallbladder_endAt: "",
              gallbladder_total: "",
              digestiveMeasure3031: "",
              digestiveMeasure3032: "",
            };
            pancreas_5 = {
              pancreas_dateTime: "",
              pancreas_startAt: "",
              pancreas_endAt: "",
              pancreas_total: "",
              digestiveMeasure3061: "",
            };
          } else {
            spleen_5 = {
              spleen_dateTime: "",
              spleen_startAt: "",
              spleen_endAt: "",
              spleen_total: "",
              spleenMeasure4011: "",
              spleenMeasure4012: "",
              spleenMeasure4021: "",
            };
          }
        }
      }
    });
    //处理每个部位的时间及将各个部位的属性加到对应的数据中
    let artery_dateTime = "";
    Object.keys(artery_1).forEach((item, index) => {
      const value = artery_1[item];
      for (let p in value) {
        if (p == "artery_finishDate") {
          if (value[p] > artery_dateTime) {
            artery_dateTime = value[p];
          }
        } else {
          res_1[`${p}${index}`] = value[p];
        }
      }
      let artery_dateTime_show = "";
      if (artery_dateTime) {
        artery_dateTime_show = moment(artery_dateTime).format("YYYY年MM月DD日");
      }
      res_1["artery_dateTime"] = artery_dateTime_show;
    });
    let thyroid_dateTime = "";
    Object.keys(thyroid_1).forEach((item, index) => {
      const value = thyroid_1[item];
      for (let p in value) {
        if (p == "thyroid_finishDate") {
          if (value[p] > thyroid_dateTime) {
            thyroid_dateTime = value[p];
          }
        } else {
          res_1[`${p}${index}`] = value[p];
        }
      }
      let thyroid_dateTime_show = "";
      if (thyroid_dateTime) {
        thyroid_dateTime_show =
          moment(thyroid_dateTime).format("YYYY年MM月DD日");
      }
      res_1["thyroid_dateTime"] = thyroid_dateTime_show;
    });
    let kidney_dateTime = "";
    Object.keys(kidney_1).forEach((item, index) => {
      const value = kidney_1[item];
      for (let p in value) {
        if (p == "kidney_finishDate") {
          if (value[p] > kidney_dateTime) {
            kidney_dateTime = value[p];
          }
        } else {
          res_1[`${p}${index}`] = value[p];
        }
      }
      let kidney_dateTime_show = "";
      if (kidney_dateTime) {
        kidney_dateTime_show = moment(kidney_dateTime).format("YYYY年MM月DD日");
      }
      res_1["kidney_dateTime"] = kidney_dateTime_show;
    });
    let liver_dateTime = "";
    Object.keys(liver_1).forEach((item, index) => {
      const value = liver_1[item];
      for (let p in value) {
        if (p == "liver_finishDate") {
          if (value[p] > liver_dateTime) {
            liver_dateTime = value[p];
          }
        } else {
          res_1[`${p}${index}`] = value[p];
        }
      }
      let liver_dateTime_show = "";
      if (liver_dateTime) {
        liver_dateTime_show = moment(liver_dateTime).format("YYYY年MM月DD日");
      }
      res_1["liver_dateTime"] = liver_dateTime_show;
    });
    let gallbladder_dateTime = "";
    Object.keys(gallbladder_1).forEach((item, index) => {
      const value = gallbladder_1[item];
      for (let p in value) {
        if (p == "gallbladder_finishDate") {
          if (value[p] > gallbladder_dateTime) {
            gallbladder_dateTime = value[p];
          }
        } else {
          res_1[`${p}${index}`] = value[p];
        }
      }
      let gallbladder_dateTime_show = "";
      if (gallbladder_dateTime) {
        gallbladder_dateTime_show =
          moment(gallbladder_dateTime).format("YYYY年MM月DD日");
      }
      res_1["gallbladder_dateTime"] = gallbladder_dateTime_show;
    });
    let pancreas_dateTime = "";
    Object.keys(pancreas_1).forEach((item, index) => {
      const value = pancreas_1[item];
      for (let p in value) {
        if (p == "pancreas_finishDate") {
          if (value[p] > pancreas_dateTime) {
            pancreas_dateTime = value[p];
          }
        } else {
          res_1[`${p}${index}`] = value[p];
        }
      }
      let pancreas_dateTime_show = "";
      if (pancreas_dateTime) {
        pancreas_dateTime_show =
          moment(pancreas_dateTime).format("YYYY年MM月DD日");
      }
      res_1["pancreas_dateTime"] = pancreas_dateTime_show;
    });
    let spleen_dateTime = "";
    Object.keys(spleen_1).forEach((item, index) => {
      const value = spleen_1[item];
      for (let p in value) {
        if (p == "spleen_finishDate") {
          if (value[p] > spleen_dateTime) {
            spleen_dateTime = value[p];
          }
        } else {
          res_1[`${p}${index}`] = value[p];
        }
      }
      let spleen_dateTime_show = "";
      if (spleen_dateTime) {
        spleen_dateTime_show = moment(spleen_dateTime).format("YYYY年MM月DD日");
      }
      res_1["spleen_dateTime"] = spleen_dateTime_show;
    });

    let artery_dateTime2 = "";
    Object.keys(artery_2).forEach((item, index) => {
      const value = artery_2[item];
      for (let p in value) {
        if (p == "artery_finishDate") {
          if (value[p] > artery_dateTime2) {
            artery_dateTime2 = value[p];
          }
        } else {
          res_2[`${p}${index}`] = value[p];
        }
      }
      let artery_dateTime_show = "";
      if (artery_dateTime2) {
        artery_dateTime_show =
          moment(artery_dateTime2).format("YYYY年MM月DD日");
      }
      res_2["artery_dateTime"] = artery_dateTime_show;
    });
    let thyroid_dateTime2 = "";
    Object.keys(thyroid_2).forEach((item, index) => {
      const value = thyroid_2[item];
      for (let p in value) {
        if (p == "thyroid_finishDate") {
          if (value[p] > thyroid_dateTime2) {
            thyroid_dateTime2 = value[p];
          }
        } else {
          res_2[`${p}${index}`] = value[p];
        }
      }
      let thyroid_dateTime_show = "";
      if (thyroid_dateTime2) {
        thyroid_dateTime_show =
          moment(thyroid_dateTime2).format("YYYY年MM月DD日");
      }
      res_2["thyroid_dateTime"] = thyroid_dateTime_show;
    });
    let kidney_dateTime2 = "";
    Object.keys(kidney_2).forEach((item, index) => {
      const value = kidney_2[item];
      for (let p in value) {
        if (p == "kidney_finishDate") {
          if (value[p] > kidney_dateTime2) {
            kidney_dateTime2 = value[p];
          }
        } else {
          res_2[`${p}${index}`] = value[p];
        }
      }
      let kidney_dateTime_show = "";
      if (kidney_dateTime2) {
        kidney_dateTime_show =
          moment(kidney_dateTime2).format("YYYY年MM月DD日");
      }
      res_2["kidney_dateTime"] = kidney_dateTime_show;
    });
    let liver_dateTime2 = "";
    Object.keys(liver_2).forEach((item, index) => {
      const value = liver_2[item];
      for (let p in value) {
        if (p == "liver_finishDate") {
          if (value[p] > liver_dateTime2) {
            liver_dateTime2 = value[p];
          }
        } else {
          res_2[`${p}${index}`] = value[p];
        }
        res_2[`${p}${index}`] = value[p];
      }
      let liver_dateTime_show = "";
      if (liver_dateTime2) {
        liver_dateTime_show = moment(liver_dateTime2).format("YYYY年MM月DD日");
      }
      res_2["liver_dateTime"] = liver_dateTime_show;
    });
    let gallbladder_dateTime2 = "";
    Object.keys(gallbladder_2).forEach((item, index) => {
      const value = gallbladder_2[item];
      for (let p in value) {
        if (p == "gallbladder_finishDate") {
          if (value[p] > gallbladder_dateTime2) {
            gallbladder_dateTime2 = value[p];
          }
        } else {
          res_2[`${p}${index}`] = value[p];
        }
      }
      let gallbladder_dateTime_show = "";
      if (gallbladder_dateTime2) {
        gallbladder_dateTime_show = moment(gallbladder_dateTime2).format(
          "YYYY年MM月DD日"
        );
      }
      res_2["gallbladder_dateTime"] = gallbladder_dateTime_show;
    });
    let pancreas_dateTime2 = "";
    Object.keys(pancreas_2).forEach((item, index) => {
      const value = pancreas_2[item];
      for (let p in value) {
        if (p == "pancreas_finishDate") {
          if (value[p] > pancreas_dateTime2) {
            pancreas_dateTime2 = value[p];
          }
        } else {
          res_2[`${p}${index}`] = value[p];
        }
      }
      let pancreas_dateTime_show = "";
      if (pancreas_dateTime2) {
        pancreas_dateTime_show =
          moment(pancreas_dateTime2).format("YYYY年MM月DD日");
      }
      res_2["pancreas_dateTime"] = pancreas_dateTime_show;
    });
    let spleen_dateTime2 = "";
    Object.keys(spleen_2).forEach((item, index) => {
      const value = spleen_2[item];
      for (let p in value) {
        if (p == "spleen_finishDate") {
          if (value[p] > spleen_dateTime2) {
            spleen_dateTime2 = value[p];
          }
        } else {
          res_2[`${p}${index}`] = value[p];
        }
      }
      let spleen_dateTime_show = "";
      if (spleen_dateTime2) {
        spleen_dateTime_show =
          moment(spleen_dateTime2).format("YYYY年MM月DD日");
      }
      res_2["spleen_dateTime"] = spleen_dateTime_show;
    });
    res_3 = {
      ...res_3,
      ...artery_3,
      ...thyroid_3,
      ...kidney_3,
      ...liver_3,
      ...gallbladder_3,
      ...pancreas_3,
      ...spleen_3,
    };
    res_4 = {
      ...res_4,
      ...artery_4,
      ...thyroid_4,
      ...kidney_4,
      ...liver_4,
      ...gallbladder_4,
      ...pancreas_4,
      ...spleen_4,
    };
    res_5 = {
      ...res_5,
      ...artery_5,
      ...thyroid_5,
      ...kidney_5,
      ...liver_5,
      ...gallbladder_5,
      ...pancreas_5,
      ...spleen_5,
    };
    // console.log("res_1",res_1)
    // console.log("res_2",res_2)
    // console.log("res_3",res_3)
    // console.log("res_4",res_4)
    // console.log("res_5",res_5)

    let val_1 = {},
      val_2 = {},
      val_3 = {},
      val_4 = {},
      val_5 = {};

    for (let p in res_1) {
      if (res_1[p]) {
        if (res_1[p].includes("优")) {
          val_1[p] = res_1[p].replace(/:.*/, "");
        } else if (res_1[p].includes("良")) {
          val_1[p] = res_1[p].replace(/:.*/, "");
        } else if (res_1[p].includes("差")) {
          val_1[p] = res_1[p].replace(/:.*/, "");
        } else {
          val_1[p] = res_1[p];
        }
      } else {
        val_1[p] = res_1[p];
      }
    }
    for (let p in res_2) {
      val_2[p] = res_2[p];
    }
    for (let p in res_3) {
      if (res_3[p]) {
        if (res_3[p].includes("优")) {
          val_3[p] = res_3[p].replace(/:.*/, "");
        } else if (res_3[p].includes("良")) {
          val_3[p] = res_3[p].replace(/:.*/, "");
        } else if (res_3[p].includes("差")) {
          val_3[p] = res_3[p].replace(/:.*/, "");
        } else {
          val_3[p] = res_3[p];
        }
      } else {
        val_3[p] = res_3[p];
      }
    }
    for (let p in res_4) {
      val_4[p] = res_4[p];
    }
    for (let p in res_5) {
      if (res_5[p] && typeof res_5[p] == "number") {
        if (p.includes("total")) {
          val_5[p] = Math.floor(res_5[p]);
        } else {
          val_5[p] = res_5[p].toFixed(2);
        }
      } else {
        val_5[p] = res_5[p];
      }
    }
    // console.log("val_1",val_1)
    // console.log("val_2",val_2)
    // console.log("val_3",val_3)
    // console.log("val_4",val_4)
    // console.log("val_5",val_5)
    for (let p in val_1) {
      if (val_1[p].includes("完整")) {
        val_1[p] = val_1[p].replace("完整", "满足");
      }
    }
    for (let p in val_3) {
      if (val_3[p].includes("完整")) {
        val_3[p] = val_3[p].replace("完整", "满足");
      }
    }

    const value_list = [
      {
        name: `${val_1.sNo}-扫查影像评价表-专家组`,
        param: val_1,
        type: 1,
      },
      {
        name: `${val_2.sNo}-标准切面质量评价表-专家组`,
        param: val_2,
        type: 2,
      },
      {
        name: `${val_3.sNo}-扫查影像评价表-对照医生`,
        param: val_3,
        type: 3,
      },
      {
        name: `${val_4.sNo}-试验器械诊断表`,
        param: val_4,
        type: 4,
      },
      {
        name: `${val_5.sNo}-检查时间与测量表`,
        param: val_5,
        type: 5,
      },
    ];
    return value_list;
  } catch (err) {
    console.log("dellDataByForms err :", err);
  }
}
const templateCache = {};
export async function exportToWord(param, name, type, mold) {
  try {
    console.log("param", param, "nane", name, "type", type, templateCache);
    let response;
    if (type == 1) {
      response = await fetch("/template1.docx");
    }
    if (type == 2) {
      response = await fetch("/template2.docx");
    }
    if (type == 3) {
      response = await fetch("/template3.docx");
    }
    if (type == 4) {
      response = await fetch("/template4.docx");
    }
    if (type == 5) {
      response = await fetch("/template5.docx");
    }
    const arraryBuffer = await response.arrayBuffer();
    const zip = new PizZip(arraryBuffer);
    const doc = new Docxtemplater(zip, {
      paragraphLoop: true,
      linebreaks: true,
      nullGetter: () => "",
    });
    doc.setData(param);
    doc.render();
    const output = doc.getZip().generate({ type: "blob" });
    if (mold == "blob") {
      return { file: output, fileName: name };
    } else {
      saveAs(output, `${name}.docx`);
    }
  } catch (err) {
    console.log(err);
  }
}
export async function exportToWord2(param, name, type, mold) {
  try {
    console.log("param", param, "nane", name, "type", type, templateCache);
    let response;
    if (type == 1) {
      response = await fetch("/template1.docx");
    }
    if (type == 2) {
      response = await fetch("/template2.docx");
    }
    if (type == 3) {
      response = await fetch("/template3.docx");
    }
    if (type == 4) {
      response = await fetch("/template4.docx");
    }
    if (type == 5) {
      response = await fetch("/template5.docx");
    }
    const arraryBuffer = await response.arrayBuffer();
    const zip = new PizZip(arraryBuffer);
    const doc = new Docxtemplater(zip, {
      paragraphLoop: true,
      linebreaks: true,
      nullGetter: () => "",
    });
    doc.setData(param);
    doc.render();
    const output = doc.getZip().generate({ type: "blob" });
    // 上传到后端进行转换
    const formData = new FormData();
    formData.append("file", output, `${name}.docx`);

    // 向 Node.js 服务发送文件
    const uploadResponse = await fetch("/uploadWord", {
      method: "POST",
      body: formData,
    });

    // 获取 PDF 文件
    const pdfBlob = await uploadResponse.blob();

    // 根据返回的 PDF Blob，下载文件
    if (mold == "blob") {
      return { file: pdfBlob, fileName: `${name}.pdf` };
    } else {
      saveAs(pdfBlob, `${name}.pdf`);
    }
    return output;
  } catch (err) {
    console.log(err);
  }
}
export function dellFormsDataByDate(records) {
  try {
    let res_1 = {};
    let res_2 = {};

    let artery_1 = {};
    let artery_2 = {};

    let thyroid_1 = {};
    let thyroid_2 = {};

    let kidney_1 = {};
    let kidney_2 = {};

    let liver_1 = {};
    let liver_2 = {};

    let gallbladder_1 = {};
    let gallbladder_2 = {};

    let pancreas_1 = {};
    let pancreas_2 = {};

    let spleen_1 = {};
    let spleen_2 = {};

    if (recordsInfo.length == 0 || !recordsInfo) {
      return;
    }
    recordsInfo.forEach((item) => {
      let { forms, pos, magic2, magic6, sNo } = item;
      res_1["sNo"] = sNo;
      res_2["sNo"] = sNo;
      if (pos == "腹部") {
        if (magic2 == "liver") {
          res_1["liver_magic6"] = magic6;
          res_2["liver_magic6"] = magic6;
        } else {
          res_1["spleen_magic6"] = magic6;
          res_2["spleen_magic6"] = magic6;
        }
      } else {
        const name = posInfo[pos];
        res_1[name] = magic6;
        res_2[name] = magic6;
      }
      if (forms.length > 0) {
        forms.forEach((item) => {
          if (item.evaluationResult) {
            const evaluationResult = JSON.parse(item.evaluationResult);
            if (item.evaluationID == 0 && item.level == 6) {
              if (item.pos == "颈动脉") {
                artery_1[item.doctorName] = {
                  artery_completeness: evaluationResult[item.pos]["扫查完整性"],
                  artery_intima: evaluationResult[item.pos]["左侧内膜"],
                  artery_filling:
                    evaluationResult[item.pos]["左侧血流充盈程度"],
                  artery_brightness: evaluationResult[item.pos]["左侧彩色亮度"],
                  artery_distribution:
                    evaluationResult[item.pos]["左侧色彩分布"],
                  artery_edge: evaluationResult[item.pos]["左侧频谱-边缘"],
                  artery_definition:
                    evaluationResult[item.pos]["左侧频谱-清晰度"],
                  artery_shape: evaluationResult[item.pos]["左侧频谱-形态"],
                  artery_intima_right: evaluationResult[item.pos]["右侧内膜"],
                  artery_filling_right:
                    evaluationResult[item.pos]["右侧血流充盈程度"],
                  artery_brightness_right:
                    evaluationResult[item.pos]["右侧彩色亮度"],
                  artery_distribution_right:
                    evaluationResult[item.pos]["右侧色彩分布"],
                  artery_edge_right:
                    evaluationResult[item.pos]["右侧频谱-边缘"],
                  artery_definition_right:
                    evaluationResult[item.pos]["右侧频谱-清晰度"],
                  artery_shape_right:
                    evaluationResult[item.pos]["右侧频谱-形态"],
                  artery_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "甲状腺") {
                thyroid_1[item.doctorName] = {
                  thyroid_completeness:
                    evaluationResult[item.pos]["扫查完整性"],
                  thyroid_shape: evaluationResult[item.pos]["形态轮廓"],
                  thyroid_detailLevel: evaluationResult[item.pos]["细腻程度"],
                  thyroid_brightness: evaluationResult[item.pos]["彩色亮度"],
                  thyroid_distribution: evaluationResult[item.pos]["色彩分布"],
                  thyroid_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "泌尿") {
                kidney_1[item.doctorName] = {
                  kidney_completeness: evaluationResult[item.pos]["扫查完整性"],
                  kidney_shape: evaluationResult[item.pos]["左肾形态轮廓"],
                  kidney_cortex:
                    evaluationResult[item.pos]["左肾皮质、髓质显示"],
                  kidney_brightness: evaluationResult[item.pos]["左肾彩色亮度"],
                  kidney_distribution:
                    evaluationResult[item.pos]["左肾色彩分布"],
                  kidney_shape_right:
                    evaluationResult[item.pos]["右肾形态轮廓"],
                  kidney_cortex_right:
                    evaluationResult[item.pos]["右肾皮质、髓质显示"],
                  kidney_brightness_right:
                    evaluationResult[item.pos]["右肾彩色亮度"],
                  kidney_distribution_right:
                    evaluationResult[item.pos]["右肾色彩分布"],
                  kidney_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "腹部") {
                const liverRes = evaluationResult["肝脏"];
                const gallbladderRes = evaluationResult["胆囊"];
                const pancreasRes = evaluationResult["胰腺"];
                const spleenRes = evaluationResult["脾脏"];
                if (magic2 == "liver") {
                  liver_1[item.doctorName] = {
                    liver_completeness_q: liverRes["扫查完整性"],
                    liver_shape_q: liverRes["形态轮廓"],
                    liver_structure_q: liverRes["管道结构"],
                    liver_detailLevel_q: liverRes["细腻程度"],
                    liver_brightness_q: liverRes["彩色亮度"],
                    liver_distribution_q: liverRes["色彩分布"],
                    liver_filling_q: liverRes["血管充盈度"],
                    liver_finishDate: moment(item.finishDate).valueOf(),
                  };
                  gallbladder_1[item.doctorName] = {
                    gallbladder_completeness_q: gallbladderRes["扫查完整性"],
                    gallbladder_wall_q: gallbladderRes["胆囊壁"],
                    gallbladder_cavity_q: gallbladderRes["胆囊腔"],
                    gallbladder_finishDate: moment(item.finishDate).valueOf(),
                  };
                  pancreas_1[item.doctorName] = {
                    pancreas_completeness_q: pancreasRes["扫查完整性"],
                    pancreas_shape_q: pancreasRes["形态轮廓"],
                    pancreas_detailLevel_q: pancreasRes["细腻程度"],
                    pancreas_finishDate: moment(item.finishDate).valueOf(),
                  };
                } else {
                  spleen_1[item.doctorName] = {
                    spleen_completeness_q: spleenRes["扫查完整性"],
                    spleen_shape_q: spleenRes["形态轮廓"],
                    spleen_detailLevel_q: spleenRes["细腻程度"],
                    spleen_blood_q: spleenRes["脾门血管"],
                    spleen_finishDate: moment(item.finishDate).valueOf(),
                  };
                }
              }
            } else if (item.evaluationID == 1 && item.level == 6) {
              // console.log(evaluationResult)
              // console.log(`有 标准切面质量评价表-专家组,name:${item.doctorName},pos:${item.pos}`);
              if (item.pos == "颈动脉") {
                artery_2[item.doctorName] = {
                  LeftCrossCCA:
                    evaluationResult[item.pos]["左侧颈总动脉横切面"],
                  LeftCrossBifurcation:
                    evaluationResult[item.pos]["左侧窦部横切面"],
                  LeftCrossICAECA:
                    evaluationResult[item.pos]["左侧颈内及颈外动脉横切面"],
                  LeftLongCCA:
                    evaluationResult[item.pos]["左侧颈内及颈外动脉纵切面"],
                  LeftLongICA: evaluationResult[item.pos]["左侧颈总动脉纵切面"],
                  LeftLongCCAStartSeg:
                    evaluationResult[item.pos]["左侧颈总动脉起始部纵切面"],
                  rightCrossCCA:
                    evaluationResult[item.pos]["右侧颈总动脉横切面"],
                  rightCrossBifurcation:
                    evaluationResult[item.pos]["右侧窦部横切面"],
                  rightCrossICAECA:
                    evaluationResult[item.pos]["右侧颈内及颈外动脉横切面"],
                  rightLongCCA:
                    evaluationResult[item.pos]["右侧颈内及颈外动脉纵切面"],
                  rightLongICA:
                    evaluationResult[item.pos]["右侧颈总动脉纵切面"],
                  rightLongCCAStartSeg:
                    evaluationResult[item.pos]["右侧颈总动脉起始部纵切面"],
                  artery_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "甲状腺") {
                thyroid_2[item.doctorName] = {
                  crossThmus: evaluationResult[item.pos]["峡部横切面"],
                  crossLeftLobe: evaluationResult[item.pos]["左侧叶横切面"],
                  LongLeftLobe: evaluationResult[item.pos]["左侧叶纵切面"],
                  crossRightLobe: evaluationResult[item.pos]["右侧叶横切面"],
                  LongRIghtLobe: evaluationResult[item.pos]["右侧叶纵切面"],
                  thyroid_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "泌尿") {
                kidney_2[item.doctorName] = {
                  kidney1: evaluationResult[item.pos]["左肾脏的长轴切面"],
                  kidney2: evaluationResult[item.pos]["右肾脏的长轴切面"],
                  kidney_finishDate: moment(item.finishDate).valueOf(),
                };
              } else if (item.pos == "腹部") {
                const liverRes = evaluationResult["肝脏"];
                const gallbladderRes = evaluationResult["胆囊"];
                const pancreasRes = evaluationResult["胰腺"];
                const spleenRes = evaluationResult["脾脏"];
                if (magic2 == "liver") {
                  liver_2[item.doctorName] = {
                    liver1: liverRes["肝左叶经腹主动脉长轴纵切面"],
                    liver2: liverRes["肝左叶斜切面"],
                    liver3: liverRes["肋下斜切第二肝门切面"],
                    liver4: liverRes["右肋下右肝及右肾纵切面"],
                    liver5: liverRes["右肋间经第一肝门斜切面"],
                    liver_finishDate: moment(item.finishDate).valueOf(),
                  };
                  gallbladder_2[item.doctorName] = {
                    gallbladder1: gallbladderRes["胆囊长轴纵切面"],
                    gallbladder_finishDate: moment(item.finishDate).valueOf(),
                  };
                  pancreas_2[item.doctorName] = {
                    pancreas1: pancreasRes["胰腺长轴切面"],
                    pancreas_finishDate: moment(item.finishDate).valueOf(),
                  };
                } else {
                  spleen_2[item.doctorName] = {
                    spleen1: spleenRes["脾脏纵切面"],
                    spleen_finishDate: moment(item.finishDate).valueOf(),
                  };
                }
              }
            }
          } else {
            if (item.evaluationID == 0 && item.level == 6) {
              // console.log("无 扫查影像评价表-专家",item.doctorName);
              if (item.pos == "颈动脉") {
                artery_1[item.doctorName] = {
                  artery_completeness: "",
                  artery_intima: "",
                  artery_filling: "",
                  artery_brightness: "",
                  artery_distribution: "",
                  artery_edge: "",
                  artery_definition: "",
                  artery_shape: "",
                  artery_intima_right: "",
                  artery_filling_right: "",
                  artery_brightness_right: "",
                  artery_distribution_right: "",
                  artery_edge_right: "",
                  artery_definition_right: "",
                  artery_shape_right: "",
                  artery_finishDate: "",
                };
              } else if (item.pos == "甲状腺") {
                thyroid_1[item.doctorName] = {
                  thyroid_completeness: "",
                  thyroid_shape: "",
                  thyroid_detailLevel: "",
                  thyroid_brightness: "",
                  thyroid_distribution: "",
                  thyroid_finishDate: "",
                };
              } else if (item.pos == "泌尿") {
                kidney_1[item.doctorName] = {
                  kidney_completeness: "",
                  kidney_shape: "",
                  kidney_cortex: "",
                  kidney_brightness: "",
                  kidney_distribution: "",
                  kidney_shape_right: "",
                  kidney_cortex_right: "",
                  kidney_brightness_right: "",
                  kidney_distribution_right: "",
                  kidney_finishDate: "",
                };
              } else if (item.pos == "腹部") {
                if (magic2 == "liver") {
                  liver_1[item.doctorName] = {
                    liver_completeness_q: "",
                    liver_shape_q: "",
                    liver_structure_q: "",
                    liver_detailLevel_q: "",
                    liver_brightness_q: "",
                    liver_distribution_q: "",
                    liver_filling_q: "",
                    liver_finishDate: "",
                  };
                  gallbladder_1[item.doctorName] = {
                    gallbladder_completeness_q: "",
                    gallbladder_wall_q: "",
                    gallbladder_cavity_q: "",
                    gallbladder_finishDate: "",
                  };
                  pancreas_1[item.doctorName] = {
                    pancreas_completeness_q: "",
                    pancreas_shape_q: "",
                    pancreas_detailLevel_q: "",
                    pancreas_finishDate: "",
                  };
                } else {
                  spleen_1[item.doctorName] = {
                    spleen_completeness_q: "",
                    spleen_shape_q: "",
                    spleen_detailLevel_q: "",
                    spleen_blood_q: "",
                    spleen_finishDate: "",
                  };
                }
              }
            } else if (item.evaluationID == 1 && item.level == 6) {
              // console.log("无 标准切面质量评价表-专家组",item.doctorName);
              if (item.pos == "颈动脉") {
                artery_2[item.doctorName] = {
                  LeftCrossCCA: "",
                  LeftCrossBifurcation: "",
                  LeftCrossICAECA: "",
                  LeftLongCCA: "",
                  LeftLongICA: "",
                  LeftLongCCAStartSeg: "",
                  rightCrossCCA: "",
                  rightCrossBifurcation: "",
                  rightCrossICAECA: "",
                  rightLongCCA: "",
                  rightLongICA: "",
                  rightLongCCAStartSeg: "",
                  artery_finishDate: "",
                };
              } else if (item.pos == "甲状腺") {
                thyroid_2[item.doctorName] = {
                  crossThmus: "",
                  crossLeftLobe: "",
                  LongLeftLobe: "",
                  crossRightLobe: "",
                  LongRIghtLobe: "",
                  thyroid_finishDate: "",
                };
              } else if (item.pos == "泌尿") {
                kidney_2[item.doctorName] = {
                  kidney1: "",
                  kidney2: "",
                  kidney_finishDate: "",
                };
              } else if (item.pos == "腹部") {
                if (magic2 == "liver") {
                  liver_2[item.doctorName] = {
                    liver1: "",
                    liver2: "",
                    liver3: "",
                    liver4: "",
                    liver5: "",
                    liver_finishDate: "",
                  };
                  gallbladder_2[item.doctorName] = {
                    gallbladder1: "",
                    gallbladder_finishDate: "",
                  };
                  pancreas_2[item.doctorName] = {
                    pancreas1: "",
                    pancreas_finishDate: "",
                  };
                } else {
                  spleen_2[item.doctorName] = {
                    spleen1: "",
                    spleen_finishDate: "",
                  };
                }
              }
            }
          }
        });
      }
    });
  } catch (error) {
    console.log("dellFormsDataByDate", records);
  }
}
